From fd31f7b157d1f219633c0cb18ab5351abbf6bd9d Mon Sep 17 00:00:00 2001 From: qyh15 Date: Sun, 15 Nov 2026 14:43:56 +0800 Subject: [PATCH] release: dsh-sansheng-liubu v0.1.1 (package at repo root) --- .gitignore | 1 + CONTRACT.md | 61 ++ README.md | 22 + client.js | 1447 ++++++++++++++++++++++++++++++++++++++ cordis.patch.yml | 4 + index.js | 46 ++ package.json | 52 ++ pnpm-lock.yaml | 407 +++++++++++ scripts/build-client.mjs | 57 ++ src/client/index.js | 563 +++++++++++++++ src/client/styles.js | 93 +++ src/client/transport.js | 49 ++ src/client/workbench.js | 231 ++++++ src/host/api.js | 42 ++ src/host/constants.js | 1 + src/host/model.js | 34 + src/host/paths.js | 14 + src/host/prompt.js | 30 + src/host/provision.js | 154 ++++ src/host/service.js | 159 +++++ src/host/store.js | 93 +++ src/native/index.js | 201 ++++++ src/native/panel.js | 198 ++++++ src/shared/roles.js | 82 +++ src/shared/schema.js | 101 +++ test/api.test.js | 44 ++ test/client.test.js | 141 ++++ test/fake-ctx.js | 106 +++ test/helpers.js | 18 + test/integration.test.js | 52 ++ test/isolation.test.js | 47 ++ test/model.test.js | 44 ++ test/native.test.js | 192 +++++ test/prompt.test.js | 35 + test/provision.test.js | 67 ++ test/roles.test.js | 29 + test/store.test.js | 48 ++ test/wiring.test.js | 23 + 38 files changed, 4988 insertions(+) create mode 100644 .gitignore create mode 100644 CONTRACT.md create mode 100644 README.md create mode 100644 client.js create mode 100644 cordis.patch.yml create mode 100644 index.js create mode 100644 package.json create mode 100644 pnpm-lock.yaml create mode 100644 scripts/build-client.mjs create mode 100644 src/client/index.js create mode 100644 src/client/styles.js create mode 100644 src/client/transport.js create mode 100644 src/client/workbench.js create mode 100644 src/host/api.js create mode 100644 src/host/constants.js create mode 100644 src/host/model.js create mode 100644 src/host/paths.js create mode 100644 src/host/prompt.js create mode 100644 src/host/provision.js create mode 100644 src/host/service.js create mode 100644 src/host/store.js create mode 100644 src/native/index.js create mode 100644 src/native/panel.js create mode 100644 src/shared/roles.js create mode 100644 src/shared/schema.js create mode 100644 test/api.test.js create mode 100644 test/client.test.js create mode 100644 test/fake-ctx.js create mode 100644 test/helpers.js create mode 100644 test/integration.test.js create mode 100644 test/isolation.test.js create mode 100644 test/model.test.js create mode 100644 test/native.test.js create mode 100644 test/prompt.test.js create mode 100644 test/provision.test.js create mode 100644 test/roles.test.js create mode 100644 test/store.test.js create mode 100644 test/wiring.test.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c2658d7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules/ diff --git a/CONTRACT.md b/CONTRACT.md new file mode 100644 index 0000000..696eccc --- /dev/null +++ b/CONTRACT.md @@ -0,0 +1,61 @@ +# 三省六部 v0.1 内部接口契约 + +本文件约束 Web 工作台、dsh-go 原生面板与宿主服务之间的数据形状。三端共用 `src/shared/roles.js` 与 `src/shared/schema.js`。 + +## 十席 + +- `SEAT_IDS` 顺序:lead, zhongshu, shangshu, menxia, libu, hubu, lipu, bingbu, xingbu, gongbu。 +- `SEATS[id]` = `{ id, label(两字), duty(短摘要), responsibility(职责全文) }`。 +- `SEAT_GROUPS` = `{ lead:[lead], sansheng:[zhongshu,shangshu,menxia], liubu:[libu,hubu,lipu,bingbu,xingbu,gongbu] }`(工作台布局用)。 + +## 宿主 HTTP:POST `/api/sansheng` + +请求体 `{ endpoint: string, payload?: object }`;成功回 `{ ok:true, value }`,失败回 `{ ok:false, error:{ code, message } }`(HTTP 200)。 + +| endpoint | payload | value | +|---|---|---| +| `list` | — | `{ projects:[{ id, name, status, revision }] }` | +| `project` | `{ projectId }` | 项目视图(见下) | +| `open` | `{ workspaceId, name?, path? }` | 项目视图;不存在则按 workspaceId 建项目记录(不创建会话) | +| `enable` | `{ projectId }` | 项目视图;严格创建/恢复十席会话 | +| `configure` | `{ projectId, seatId, model:({provider,model,reasoningEffort?}|null), instructions? }` | `{ seat }` | +| `models` | — | `{ providers:[{ provider, models:[{ model, reasoningEffort?:[...] }] }], default:({provider,model}|null), failures:[...] }` | + +错误码:`sansheng/invalid`、`sansheng/not-found`、`sansheng/conflict`、`sansheng/unbound`(席尚未绑定会话)、`sansheng/model-invalid`、`sansheng/state-corrupt`。 + +## 项目视图 + +```jsonc +{ + "revision": 0, + "project": { + "id": "ws-1", "name": "项目名", "workspaceId": "ws-1", "path": "D:/x", "status": "pending|provisioning|ready|error", + "seats": [ + { "id":"lead","label":"丞相","duty":"...","responsibility":"...","status":"pending|creating|bound|failed|missing","sessionId":null,"model":null,"instructions":"","error":null } + ], + "groups": { "lead":["lead"], "sansheng":[...], "liubu":[...] } + } +} +``` + +## 会话/模型规则(两端 UI 必须遵守) + +- 每席一个独立 root Session;切换角色 = 导航到该席 `sessionId`,不新建、不重建聊天引擎。 +- 模型未选择显示“请选择模型”;选择后显示具体名称。界面不提供“跟随宿主模型”选项。 +- “启用”只建立十个会话,不自动运行模型。 +- 角色补充说明:Web 可编辑;原生面板只读(原生无自由文本控件)。 + +## Web 工作台(`src/client/`) + +纯视图模型函数 `buildWorkbenchView(view, ui)` 必须可由 node 直接 import 测试(不依赖 React/DOM): +- `view` = 项目视图;`ui` = `{ selectedSeatId, models, draft }`。 +- 返回:`{ projectTitle, ready, seats:[{id,name,duty,statusLabel,selected}], groups, selected:{ id,name,responsibility,duty,modelValue,modelLabel,instructions,modelOptions } }`。 +- `seats` 必须正好十项且 name 两字;未选模型时 `modelLabel==='请选择模型'` 且 `modelValue===''`;`modelOptions` 不得含 value==='inherit' 的项。 +React 接线用 `React.createElement`(不用 JSX,便于 esbuild 直接打包)。入口 `export const inject=[...]` + `export function apply(ctx)`。 + +## dsh-go 原生面板(`src/native/`) + +纯视图树函数 `buildPanelView(input)` 必须可由 node 直接 import 测试: +- `input` = `{ project, selectedSeatId, models }`。 +- 返回原生 view 节点(`{ type:'stack'|'row'|'text'|'list'|'callout'|'button'|'accordion'... }`)。 +- 硬约束:节点数 ≤120、深度 ≤8、单个 options/列表 ≤8 项、无自由文本输入控件;十席按 lead/sansheng/liubu 分组呈现。 diff --git a/README.md b/README.md new file mode 100644 index 0000000..0e9ec55 --- /dev/null +++ b/README.md @@ -0,0 +1,22 @@ +# 三省六部(dsh-sansheng)· 第一版 + +在 DSH 里为每个项目提供固定的十席角色(丞相、中书、门下、尚书、吏部、户部、礼部、兵部、刑部、工部), +每席绑定一个独立的原生命 root Session,模型与补充说明按项目独立保存。中间复用宿主原生会话,不替换聊天引擎。 + +当前进度(对应 `docs/v1-plan.md` §7 实施顺序): + +- ✅ 第 2 步:项目内身份与十席会话绑定(宿主服务 + 严格创建/恢复/失败重试/跨项目隔离,`npm test` 用 fake ctx 验证)。 +- ✅ 第 3 步:Web 入口与右侧工作台(已在隔离测试 DSH 真机验证:入口、十席工作台、真实建十个会话、重启幂等)。 +- 🟡 第 4 步:dsh-go 原生面板(源代码就位,触摸/返回/会话跳转需真机核验)。 +- ⬜ 第 5 步:双项目联调后打包发布。 + +**本包尚未安装到任何 DSH profile,也未改动用户的日常 DSH 配置。** + +## 目录 + +- `index.js` — 宿主插件入口(`name` / `inject` / `apply`)。 +- `src/shared/` — 十席定义与项目状态 schema(前后端共用)。 +- `src/host/` — 项目状态存储、严格会话创建/恢复、模型配置(不写 profile)、提示词 section、HTTP `api/sansheng`。 +- `src/client/` — Web 工作台(纯视图模型 + React 接线 + 传输层)。 +- `src/native/` — dsh-go 原生面板(纯视图树构造 + bridge 接线)。 +- `test/` — fake ctx 单元/集成测试。 diff --git a/client.js b/client.js new file mode 100644 index 0000000..4581af7 --- /dev/null +++ b/client.js @@ -0,0 +1,1447 @@ +// Generated from src/client by `npm run build` (scripts/build-client.mjs). Do not edit by hand. +window.__ModuleLoader__.load({ + id: 'dsh-sansheng-liubu', + factory: (require) => { +const module = { exports: {} } +var __defProp = Object.defineProperty; +var __getOwnPropDesc = Object.getOwnPropertyDescriptor; +var __getOwnPropNames = Object.getOwnPropertyNames; +var __hasOwnProp = Object.prototype.hasOwnProperty; +var __export = (target, all) => { + for (var name in all) + __defProp(target, name, { get: all[name], enumerable: true }); +}; +var __copyProps = (to, from, except, desc) => { + if (from && typeof from === "object" || typeof from === "function") { + for (let key of __getOwnPropNames(from)) + if (!__hasOwnProp.call(to, key) && key !== except) + __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); + } + return to; +}; +var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); + +// src/client/index.js +var index_exports = {}; +__export(index_exports, { + apply: () => apply, + inject: () => inject +}); +module.exports = __toCommonJS(index_exports); + +// src/shared/roles.js +var SEAT_IDS = Object.freeze([ + "lead", + "zhongshu", + "shangshu", + "menxia", + "libu", + "hubu", + "lipu", + "bingbu", + "xingbu", + "gongbu" +]); +var SEATS = Object.freeze({ + lead: { + id: "lead", + label: "丞相", + duty: "接需求 · 协调汇报", + responsibility: "面向用户承接想法:判断是否需要开工、必要时派给具体部门,并把各部门结果汇总成对用户的一次交付。" + }, + zhongshu: { + id: "zhongshu", + label: "中书", + duty: "调查 · 澄清 · 规划", + responsibility: "先把问题问清、把材料看全,再给出可执行的方案与验收标准草案,不直接产出最终交付物。" + }, + shangshu: { + id: "shangshu", + label: "尚书", + duty: "分工 · 组织交付", + responsibility: "把已经明确的方案拆成部门分工并组织交付;六部直属于尚书这一同级分组,六部之间不是上下级。" + }, + menxia: { + id: "menxia", + label: "门下", + duty: "审议 · 整体审核", + responsibility: "对方案和交付做独立审议,指出风险与不达标处。首版没有门下审核的任务必须如实标注“未审核”。" + }, + libu: { + id: "libu", + label: "吏部", + duty: "角色 · 技能配置", + responsibility: "对角色、技能与编制给出建议;职责不含绕过用户授权去改权限或其他项目设置。" + }, + hubu: { + id: "hubu", + label: "户部", + duty: "数据 · 表格计算", + responsibility: "处理数据、表格与计算,结论应可复算。" + }, + lipu: { + id: "lipu", + label: "礼部", + duty: "文档 · 内容呈现", + responsibility: "负责文档、内容与呈现形式,产出可编辑的源文件。" + }, + bingbu: { + id: "bingbu", + label: "兵部", + duty: "环境 · 调试部署", + responsibility: "负责环境、调试与部署;部署/发布等外部副作用仍服从用户授权与宿主审批。" + }, + xingbu: { + id: "xingbu", + label: "刑部", + duty: "测试 · 风险检查", + responsibility: "做测试与风险检查,给出可追溯的检查结果,而不是一句“已通过”。" + }, + gongbu: { + id: "gongbu", + label: "工部", + duty: "代码 · 工程产出", + responsibility: "负责代码实现与工程产出,交付可编辑源文件与真实检查结果。" + } +}); +var SEAT_GROUPS = Object.freeze({ + lead: Object.freeze(["lead"]), + sansheng: Object.freeze(["zhongshu", "shangshu", "menxia"]), + liubu: Object.freeze(["libu", "hubu", "lipu", "bingbu", "xingbu", "gongbu"]) +}); +function isSeatId(id) { + return SEAT_IDS.includes(id); +} +function seatOf(id) { + return SEATS[id]; +} +function seatLabel(id) { + return SEATS[id]?.label ?? ""; +} +function seatBySessionId(projects, sessionId) { + if (!sessionId || !projects) return void 0; + for (const project of Object.values(projects)) { + for (const seatId of SEAT_IDS) { + if (project?.seats?.[seatId]?.sessionId === sessionId) { + return { project, seatId, seat: SEATS[seatId] }; + } + } + } + return void 0; +} + +// src/client/workbench.js +var UNCHOSEN_MODEL_LABEL = "请选择模型"; +var SEAT_STATUS_LABELS = Object.freeze({ + pending: "待启用", + creating: "创建中", + bound: "已绑定", + failed: "创建失败", + missing: "会话缺失" +}); +var DEFAULT_SEAT_STATUS = "pending"; +function seatStatusLabel(status) { + if (typeof status !== "string") return "未知状态"; + return SEAT_STATUS_LABELS[status] ?? "未知状态"; +} +function projectStatusLabel(status) { + switch (status) { + case "pending": + return "待启用"; + case "provisioning": + return "启用中"; + case "ready": + return "已启用"; + case "error": + return "启用失败"; + default: + return "未知状态"; + } +} +function collectModelOptions(models) { + const out = []; + const seen = /* @__PURE__ */ new Set(); + const providers = Array.isArray(models?.providers) ? models.providers : []; + for (const entry of providers) { + const provider = typeof entry?.provider === "string" ? entry.provider : ""; + if (!provider) continue; + const list = Array.isArray(entry?.models) ? entry.models : []; + for (const item of list) { + const model = typeof item?.model === "string" ? item.model : ""; + if (!model) continue; + const efforts = Array.isArray(item?.reasoningEffort) ? item.reasoningEffort.filter((e) => typeof e === "string" && e.trim() !== "") : []; + if (efforts.length > 0) { + for (const effort of efforts) { + const value = provider + "::" + model + "::" + effort; + if (value === "inherit" || seen.has(value)) continue; + seen.add(value); + out.push({ value, label: model + " · " + effort, provider, model, reasoningEffort: effort }); + } + } else { + const value = provider + "::" + model; + if (value === "inherit" || seen.has(value)) continue; + seen.add(value); + out.push({ value, label: model, provider, model }); + } + } + } + return out; +} +function findModelOption(options, modelValue2) { + if (!Array.isArray(options)) return void 0; + return options.find((option) => option.value === modelValue2); +} +function describeModel(model, options) { + if (!model || typeof model !== "object" || typeof model.provider !== "string" || typeof model.model !== "string") { + return { modelValue: "", modelLabel: UNCHOSEN_MODEL_LABEL }; + } + const effort = typeof model.reasoningEffort === "string" && model.reasoningEffort ? model.reasoningEffort : void 0; + const match = (Array.isArray(options) ? options : []).find((option) => option.provider === model.provider && option.model === model.model && (option.reasoningEffort ?? void 0) === effort); + if (match) return { modelValue: match.value, modelLabel: match.label }; + const modelLabel = effort ? model.model + " · " + effort : model.model; + const modelValue2 = effort ? model.provider + "::" + model.model + "::" + effort : model.provider + "::" + model.model; + return { modelValue: modelValue2, modelLabel }; +} +function normalizeSeats(seats) { + const map = {}; + if (Array.isArray(seats)) { + for (const seat of seats) { + if (seat && typeof seat === "object" && typeof seat.id === "string") map[seat.id] = seat; + } + } else if (seats && typeof seats === "object") { + for (const [id, seat] of Object.entries(seats)) { + if (seat && typeof seat === "object") map[id] = { id, ...seat }; + } + } + return map; +} +function cloneGroups() { + const out = {}; + for (const key of Object.keys(SEAT_GROUPS)) out[key] = Array.from(SEAT_GROUPS[key]); + return out; +} +function pickSelectedId(requested) { + if (typeof requested === "string" && SEAT_IDS.includes(requested)) return requested; + return SEAT_IDS[0]; +} +function hasOwn(obj, key) { + return obj !== null && obj !== void 0 && Object.prototype.hasOwnProperty.call(obj, key); +} +function draftOf(draft, seatId) { + if (!draft || typeof draft !== "object") return {}; + const entry = draft[seatId]; + return entry && typeof entry === "object" ? entry : {}; +} +function updateDraft(draft, seatId, patch) { + const base = draft && typeof draft === "object" ? draft : {}; + const previous = base[seatId] && typeof base[seatId] === "object" ? base[seatId] : {}; + return { ...base, [seatId]: { ...previous, ...patch ?? {} } }; +} +function clearDraft(draft, seatId) { + if (!draft || typeof draft !== "object" || !hasOwn(draft, seatId)) return draft ?? {}; + const next = { ...draft }; + delete next[seatId]; + return next; +} +function buildWorkbenchView(view, ui) { + const safeView = view && typeof view === "object" ? view : {}; + const project = safeView.project && typeof safeView.project === "object" ? safeView.project : {}; + const status = typeof project.status === "string" ? project.status : "pending"; + const ready = status === "ready"; + const seatMap = normalizeSeats(project.seats); + const selectedSeatId = pickSelectedId(ui?.selectedSeatId); + const models = ui?.models ?? null; + const modelOptions = collectModelOptions(models); + const draft = ui?.draft ?? null; + const seats = SEAT_IDS.map((id) => { + const def = SEATS[id]; + const rec = seatMap[id] ?? {}; + const seatStatus = typeof rec.status === "string" ? rec.status : DEFAULT_SEAT_STATUS; + return { + id, + name: def.label, + duty: def.duty, + status: seatStatus, + statusLabel: seatStatusLabel(seatStatus), + selected: id === selectedSeatId + }; + }); + const seatDef = SEATS[selectedSeatId]; + const seatRec = seatMap[selectedSeatId] ?? {}; + const draftEntry = draftOf(draft, selectedSeatId); + let described; + if (hasOwn(draftEntry, "modelValue")) { + const raw = draftEntry.modelValue; + if (raw === "" || raw === null || raw === void 0) { + described = { modelValue: "", modelLabel: UNCHOSEN_MODEL_LABEL }; + } else { + const match = findModelOption(modelOptions, raw); + described = match ? { modelValue: match.value, modelLabel: match.label } : { modelValue: String(raw), modelLabel: String(raw) }; + } + } else if (hasOwn(draftEntry, "model")) { + described = describeModel(draftEntry.model, modelOptions); + } else { + described = describeModel(seatRec.model ?? null, modelOptions); + } + const instructions = hasOwn(draftEntry, "instructions") ? draftEntry.instructions : typeof seatRec.instructions === "string" ? seatRec.instructions : ""; + const selectedStatus = typeof seatRec.status === "string" ? seatRec.status : DEFAULT_SEAT_STATUS; + let boundCount = 0; + let sessionCount = 0; + for (const id of SEAT_IDS) { + const rec = seatMap[id]; + if (rec?.status === "bound") boundCount += 1; + if (rec?.sessionId) sessionCount += 1; + } + return { + projectTitle: typeof project.name === "string" ? project.name : "", + ready, + project: { + id: project.id ?? "", + name: typeof project.name === "string" ? project.name : "", + status, + statusLabel: projectStatusLabel(status), + workspaceId: project.workspaceId ?? null, + path: project.path ?? null, + seatCount: seats.length, + boundCount, + sessionCount + }, + seats, + groups: cloneGroups(), + selected: { + id: selectedSeatId, + name: seatDef.label, + duty: seatDef.duty, + responsibility: seatDef.responsibility, + status: selectedStatus, + statusLabel: seatStatusLabel(selectedStatus), + sessionId: seatRec.sessionId ?? null, + modelValue: described.modelValue, + modelLabel: described.modelLabel, + instructions, + modelOptions, + dirty: Object.keys(draftEntry).length > 0 + } + }; +} + +// src/client/transport.js +var ROUTE = "api/sansheng"; +var SanshengRequestError = class extends Error { + constructor(message, code) { + super(message); + this.name = "SanshengRequestError"; + this.code = code || "sansheng/error"; + } +}; +async function request(endpoint, payload, signal) { + let response; + try { + response = await fetch(ROUTE, { + method: "POST", + credentials: "same-origin", + headers: { "content-type": "application/json" }, + body: JSON.stringify({ endpoint, payload: payload ?? null }), + signal + }); + } catch (error) { + if (error && error.name === "AbortError") throw error; + const detail = error && error.message ? error.message : String(error); + throw new SanshengRequestError("无法连接 DSH,请确认它仍在运行(" + detail + ")", "NETWORK"); + } + if (!response.ok) { + throw new SanshengRequestError("HTTP " + response.status, "HTTP_" + response.status); + } + let result; + try { + result = await response.json(); + } catch (error) { + throw new SanshengRequestError("响应不是合法 JSON", "sansheng/bad-response"); + } + if (!result || result.ok !== true) { + const code = result && result.error && result.error.code ? result.error.code : "sansheng/error"; + const message = result && result.error && result.error.message ? result.error.message : "请求失败"; + throw new SanshengRequestError(message, code); + } + return result.value; +} +var transport_default = request; + +// src/client/styles.js +var CSS = ` +.ssw-scope{--ssw-bg:#ffffff;--ssw-side:#f8f9fa;--ssw-rail:#f7f9fc;--ssw-card:#ffffff;--ssw-line:#e3e8ef;--ssw-strong:#c7d8f5;--ssw-ink:#0f172a;--ssw-muted:#667085;--ssw-faint:#98a2b3;--ssw-blue:#3b82f6;--ssw-wash:#eff6ff;--ssw-frame:#3b82f6;--ssw-wire:#c9d6ea;--ssw-danger:#dc2626;--ssw-ok:#16a34a;box-sizing:border-box;color:var(--ssw-ink);font-family:Inter,"Segoe UI","Microsoft YaHei",sans-serif;font-size:13px;line-height:1.5} +.ssw-scope *,.ssw-scope *::before,.ssw-scope *::after{box-sizing:border-box} +.ssw-scope button{font:inherit;color:inherit;background:transparent;border:0;cursor:pointer} +.ssw-scope button:disabled{cursor:default;opacity:.55} +.ssw-scope :focus-visible{outline:2px solid var(--ssw-blue);outline-offset:2px} +body[data-ds-dark-theme] .ssw-scope,html[data-theme=dark] .ssw-scope,.ssw-scope[data-ssw-theme=dark]{--ssw-bg:#14171c;--ssw-side:#171b21;--ssw-rail:#161a20;--ssw-card:#1e232b;--ssw-line:#2c333d;--ssw-strong:#3b4a63;--ssw-frame:#6ea8ff;--ssw-ink:#e6ebf2;--ssw-muted:#a9b4c2;--ssw-faint:#7b8797;--ssw-blue:#6ea8ff;--ssw-wash:#1d2b40;--ssw-wire:#3a4350;--ssw-danger:#f87171;--ssw-ok:#4ade80} +.ssw-float{position:fixed;right:14px;bottom:70px;z-index:2147483000;width:min(374px,calc(100vw - 28px));max-height:calc(100vh - 96px);display:flex;flex-direction:column;background:#ffffff;border:1px solid #e3e8ef;border-radius:12px;box-shadow:0 18px 50px -12px rgba(16,24,40,.28),0 4px 12px -2px rgba(16,24,40,.12);overflow:hidden} +body[data-ds-dark-theme] .ssw-float,html[data-theme=dark] .ssw-float{background:#161a20;border-color:#2c333d} +.ssw-root{display:flex;flex-direction:column;min-height:0;height:100%;overflow:auto;background:var(--ssw-rail);color:var(--ssw-ink)} +.ssw-head{flex:none;height:52px;display:flex;align-items:center;gap:8px;padding:0 16px;border-bottom:1px solid var(--ssw-line);background:var(--ssw-card)} +.ssw-head svg{width:18px;height:18px;color:var(--ssw-muted)} +.ssw-head-title{font-size:13px;font-weight:600} +.ssw-icon-btn{margin-left:auto;display:inline-flex;align-items:center;justify-content:center;width:30px;height:30px;border-radius:6px;color:var(--ssw-muted)} +.ssw-icon-btn:hover{background:var(--ssw-wash);color:var(--ssw-blue)} +.ssw-project{padding:18px 16px 0} +.ssw-project-line{display:flex;align-items:center;justify-content:space-between;margin-bottom:5px} +.ssw-eyebrow{display:inline-flex;align-items:center;gap:6px;font-size:11px;color:var(--ssw-muted)} +.ssw-eyebrow svg{width:14px;height:14px} +.ssw-count{font-size:10px;color:var(--ssw-faint)} +.ssw-project-title{font-size:17px;font-weight:600;letter-spacing:.3px;margin:0 0 14px} +.ssw-enable{margin:0 16px 4px;padding:12px;border:1px solid var(--ssw-strong);background:var(--ssw-wash);border-radius:10px} +.ssw-enable-note{margin:0 0 10px;font-size:12px;color:var(--ssw-muted);line-height:1.7} +.ssw-primary{background:var(--ssw-blue);color:#ffffff;border-radius:7px;padding:8px 13px;font-size:12px;font-weight:500} +.ssw-primary:hover{filter:brightness(1.05)} +.ssw-tree{padding:14px 16px 4px;position:relative} +.ssw-lead{width:150px;margin:0 auto;position:relative} +.ssw-lead::after{content:none} +.ssw-sansheng{position:relative;margin-top:22px} +.ssw-trio{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:9px} +.ssw-seat{position:relative;width:100%;display:flex;flex-direction:column;gap:6px;padding:10px 9px 8px;border:1.5px solid var(--ssw-frame);border-radius:10px;background:var(--ssw-card);text-align:left;min-height:70px;box-shadow:0 1px 2px rgba(16,24,40,.04);transition:border-color .15s,box-shadow .15s,transform .15s} +.ssw-seat:hover{border-color:var(--ssw-blue);transform:translateY(-1px);box-shadow:0 3px 8px rgba(16,24,40,.06)} +.ssw-seat[aria-pressed=true]{border-color:var(--ssw-blue);background:var(--ssw-wash);box-shadow:0 0 0 2px rgba(59,130,246,.12)} +.ssw-lead .ssw-seat{border-color:var(--ssw-blue)} +.ssw-role-top{display:flex;align-items:center;justify-content:space-between;gap:6px} +.ssw-role-name{font-size:14px;font-weight:600;letter-spacing:2px} +.ssw-role-duty{font-size:10px;color:var(--ssw-muted);line-height:1.5} +.ssw-dot{flex:none;width:6px;height:6px;border-radius:50%;border:1px solid var(--ssw-faint);background:transparent} +.ssw-dot[data-status=bound]{background:var(--ssw-ok);border-color:var(--ssw-ok)} +.ssw-dot[data-status=failed],.ssw-dot[data-status=missing]{background:var(--ssw-danger);border-color:var(--ssw-danger)} +.ssw-dot[data-status=creating]{background:var(--ssw-blue);border-color:var(--ssw-blue)} +.ssw-ministries{position:relative;margin-top:18px} +.ssw-group-label{display:block;margin:0 2px 8px;font-size:11px;font-weight:600;letter-spacing:.5px;color:var(--ssw-muted)} +.ssw-six{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:8px} +.ssw-six .ssw-seat{min-height:66px;padding:9px 8px} +.ssw-report{padding:0 16px;margin-top:4px} +.ssw-report-toggle{font-size:12px;color:var(--ssw-blue);padding:7px 2px;font-weight:500} +.ssw-report-list{display:flex;flex-direction:column;gap:8px;margin-top:4px} +.ssw-report-item{border:1px solid var(--ssw-line);border-radius:9px;padding:9px 11px;background:var(--ssw-card)} +.ssw-report-head{display:flex;gap:8px;align-items:baseline} +.ssw-report-head strong{font-size:13px;letter-spacing:1px} +.ssw-report-head span{font-size:10px;color:var(--ssw-muted)} +.ssw-report-model{margin:4px 0 0;font-size:11px;color:var(--ssw-blue);letter-spacing:.2px} +.ssw-report-text{margin:4px 0 0;font-size:12px;line-height:1.7;color:var(--ssw-muted)} +.ssw-current{margin:16px 16px 0;padding:13px;border:1px solid var(--ssw-line);border-radius:11px;background:var(--ssw-card)} +.ssw-current-top{display:flex;align-items:center;justify-content:space-between;margin-bottom:9px} +.ssw-current-name{font-size:13px;font-weight:600} +.ssw-current-label{font-size:10px;color:var(--ssw-faint)} +.ssw-current-text{margin:0;font-size:12px;line-height:1.8;color:var(--ssw-muted)} +.ssw-config{margin:10px 16px 0;border:1px solid var(--ssw-line);border-radius:10px;background:var(--ssw-card);overflow:hidden} +.ssw-config-toggle{display:flex;align-items:center;gap:8px;width:100%;padding:12px 13px;font-size:12px;color:var(--ssw-ink)} +.ssw-config-toggle svg{width:15px;height:15px;color:var(--ssw-muted)} +.ssw-chevron{margin-left:auto;transition:transform .2s} +.ssw-config-toggle[aria-expanded=true] .ssw-chevron{transform:rotate(180deg)} +.ssw-config-body{padding:0 13px 14px} +.ssw-label{display:block;font-size:11px;color:var(--ssw-muted);margin:12px 0 6px} +.ssw-field{width:100%;border:1px solid var(--ssw-line);background:var(--ssw-bg);color:var(--ssw-ink);border-radius:6px;padding:8px;font-size:12px;line-height:1.5} +.ssw-textarea{resize:vertical;min-height:84px;font-family:inherit} +.ssw-scope-note{margin:10px 0;font-size:10px;line-height:1.6;color:var(--ssw-faint)} +.ssw-save-row{display:flex;align-items:center;gap:10px} +.ssw-save-status{font-size:10px;color:var(--ssw-muted)} +.ssw-notice{margin:12px 16px 16px;font-size:11px;color:var(--ssw-muted)} +.ssw-error{margin:12px 16px 16px;font-size:11px;color:var(--ssw-danger)} +.ssw-loading,.ssw-empty{padding:36px 20px;text-align:center;font-size:12px;color:var(--ssw-muted)} +.ssw-empty .ssw-primary{margin-top:12px} +.ssw-entry{display:flex;align-items:center;gap:9px;width:100%;padding:0 10px;height:35px;border-radius:7px;font-size:13px;color:inherit;text-align:left} +.ssw-entry:hover{background:#eef4ff} +.ssw-entry[aria-expanded=true]{color:#2563eb;background:#eaf1fe;font-weight:600} +.ssw-entry svg{width:16px;height:16px;flex:none} +.ssw-entry-label{overflow:hidden;text-overflow:ellipsis;white-space:nowrap} +.ssw-entry-compact{width:auto;max-width:100%;height:28px;padding:0 8px;gap:6px;border:1px solid var(--ssw-line);border-radius:7px;background:var(--ssw-card);font-size:12px} +.ssw-entry-compact:hover{background:var(--ssw-wash)} +body[data-ds-dark-theme] .ssw-entry:hover{background:#1d2b40} +body[data-ds-dark-theme] .ssw-entry[aria-expanded=true]{color:#91bafa;background:#1d2b40} +@media (prefers-reduced-motion:reduce){.ssw-scope *{transition:none!important}} +.ssw-tab-body{height:100%;min-height:0;display:flex;flex-direction:column} +.ssw-tab-body .ssw-root{flex:1;min-height:0} +.ssw-tab-title{font-size:13px} +`; + +// src/native/panel.js +var GROUP_ORDER = ["lead", "sansheng", "liubu"]; +var GROUP_TITLE = { lead: "统领", sansheng: "三省", liubu: "六部" }; +var MAX_OPTIONS = 8; +var PROJECT_STATUS_TEXT = { + pending: "待启用", + provisioning: "启用中", + ready: "已就绪", + error: "异常" +}; +var SEAT_STATUS_TEXT = { + pending: "待启用", + creating: "创建中", + bound: "已绑定", + failed: "失败", + missing: "缺失" +}; +function asText(v) { + return typeof v === "string" ? v : ""; +} +function seatRecords(project) { + const out = {}; + const seats = project ? project.seats : null; + if (Array.isArray(seats)) { + for (const s of seats) if (s && SEATS[s.id]) out[s.id] = s; + } else if (seats && typeof seats === "object") { + for (const id of SEAT_IDS) if (seats[id]) out[id] = seats[id]; + } + return out; +} +function isBound(seat) { + return !!seat && typeof seat.sessionId === "string" && seat.sessionId.length > 0; +} +function modelValue(model) { + if (!model || typeof model !== "object") return ""; + if (typeof model.provider !== "string" || typeof model.model !== "string") return ""; + return model.provider + "::" + model.model; +} +function flattenModels(models) { + const opts = []; + const providers = models && Array.isArray(models.providers) ? models.providers : []; + for (const p of providers) { + const pid = asText(p && p.provider); + if (!pid) continue; + const list = Array.isArray(p && p.models) ? p.models : []; + for (const m of list) { + const mid = typeof m === "string" ? m : asText(m && m.model); + if (!mid) continue; + opts.push({ value: pid + "::" + mid, label: pid + " / " + mid }); + if (opts.length >= MAX_OPTIONS - 1) break; + } + if (opts.length >= MAX_OPTIONS - 1) break; + } + return opts; +} +function buildModelSelect(project, seat, models) { + const real = flattenModels(models); + const options = [{ value: "", label: "请选择模型" }].concat(real).slice(0, MAX_OPTIONS); + const want = modelValue(seat && seat.model); + const value = options.some((o) => o.value === want) ? want : ""; + return { + type: "select", + label: "模型", + value, + options, + action: { type: "sansheng/select-model", seatId: seat && seat.id || null, projectId: project && project.id || null } + }; +} +function seatButton(project, seat, selectedSeatId) { + const meta = SEATS[seat.id]; + const selected = seat.id === selectedSeatId; + return { + type: "button", + seatId: seat.id, + label: meta.label, + selected, + variant: selected ? "primary" : "ghost", + action: { type: "sansheng/select-seat", seatId: seat.id, projectId: project && project.id || null } + }; +} +function groupNode(project, records, key, selectedSeatId) { + const ids = (SEAT_GROUPS[key] || []).filter((id) => records[id] && SEATS[id]); + if (ids.length === 0) return null; + const perRow = key === "liubu" ? 3 : ids.length; + const rows = []; + for (let i = 0; i < ids.length; i += perRow) { + const slice = ids.slice(i, i + perRow); + rows.push({ type: "row", children: slice.map((id) => seatButton(project, records[id], selectedSeatId)) }); + } + return { + type: "stack", + group: key, + children: [{ type: "text", text: GROUP_TITLE[key] + " · " + ids.length + " 席" }].concat(rows) + }; +} +function selectedDetail(project, records, selectedSeatId, models) { + const seat = selectedSeatId ? records[selectedSeatId] : null; + if (!seat) { + return { type: "callout", tone: "info", text: "点击上方角色卡片查看职责、模型与进入会话。" }; + } + const meta = SEATS[seat.id]; + const bound = isBound(seat); + const statusLabel = SEAT_STATUS_TEXT[seat.status] || asText(seat.status) || "未知"; + const instructions = asText(seat.instructions).trim() || "(未填写)"; + return { + type: "stack", + detail: seat.id, + children: [ + { type: "text", text: meta.label + " · " + meta.duty + " · " + statusLabel }, + { type: "callout", tone: "info", text: "职责:" + meta.responsibility }, + { type: "text", text: "角色补充说明(只读,请在 Web 端编辑)" }, + { type: "callout", tone: "warn", text: instructions }, + buildModelSelect(project, seat, models), + { + type: "button", + label: bound ? "进入" + meta.label + "会话" : meta.label + "尚未绑定会话", + variant: bound ? "primary" : "ghost", + disabled: !bound, + action: { + type: "sansheng/enter-session", + seatId: seat.id, + projectId: project && project.id || null, + sessionId: isBound(seat) ? seat.sessionId : null + } + } + ] + }; +} +function buildPanelView(input) { + const { project = null, selectedSeatId = null, models = null } = input || {}; + if (!project || typeof project !== "object") { + return { + type: "stack", + children: [ + { type: "text", text: "三省六部" }, + { + type: "callout", + tone: "warn", + text: "无法确定当前项目:原生面板作用域不含 workspaceId,且未能由 sessionId 反查到所属项目。请从已启用「三省六部」的项目会话中打开,或在 Web 工作台查看。" + } + ] + }; + } + const records = seatRecords(project); + const sel = selectedSeatId && records[selectedSeatId] ? selectedSeatId : records.lead ? "lead" : null; + const ready = project.status === "ready"; + const boundCount = SEAT_IDS.filter((id) => isBound(records[id])).length; + const children = [ + { type: "text", text: "三省六部 · " + (asText(project.name) || "未命名项目") }, + { + type: "callout", + tone: ready ? "good" : "warn", + text: (PROJECT_STATUS_TEXT[project.status] || "状态未知") + " · 已绑定 " + boundCount + "/10 席" + } + ]; + for (const key of GROUP_ORDER) { + const g = groupNode(project, records, key, sel); + if (g) children.push(g); + } + children.push(selectedDetail(project, records, sel, models)); + return { type: "stack", children }; +} +var panel_default = buildPanelView; + +// src/native/index.js +var PANEL_ID = "sansheng"; +var viewBySession = /* @__PURE__ */ new Map(); +var selectionBySession = /* @__PURE__ */ new Map(); +var modelsBySession = /* @__PURE__ */ new Map(); +function cacheProject(project) { + if (!project || typeof project !== "object") return; + const seats = project.seats; + for (const id of SEAT_IDS) { + let seat = null; + if (Array.isArray(seats)) seat = seats.find((s) => s && s.id === id) || null; + else if (seats && typeof seats === "object") seat = seats[id] || null; + if (seat && typeof seat.sessionId === "string" && seat.sessionId) { + viewBySession.set(seat.sessionId, project); + } + } +} +function resolveProject(native, scope) { + const sid = scope && typeof scope.sessionId === "string" ? scope.sessionId : null; + const lookup = native && (native.sansheng || native.sanshengProjects) || null; + if (lookup && typeof lookup.projectForScope === "function") { + try { + const p = lookup.projectForScope(scope); + if (p) { + cacheProject(p); + return p; + } + } catch (e) { + } + } + if (lookup && typeof lookup.projectForSession === "function" && sid) { + try { + const p = lookup.projectForSession(sid); + if (p) { + cacheProject(p); + return p; + } + } catch (e) { + } + } + let workspaceId = null; + try { + const sessions = native && native.sessions; + if (sessions && typeof sessions.binding === "function" && sid) { + const b = sessions.binding(sid); + workspaceId = b && (b.workspaceId || b.workspace && b.workspace.id) || null; + } + } catch (e) { + } + if (lookup && typeof lookup.projectForWorkspace === "function" && workspaceId) { + try { + const p = lookup.projectForWorkspace(workspaceId); + if (p) { + cacheProject(p); + return p; + } + } catch (e) { + } + } + if (sid && viewBySession.has(sid)) return viewBySession.get(sid); + return null; +} +function makeView(native, scope) { + const sid = scope && typeof scope.sessionId === "string" ? scope.sessionId : null; + const project = resolveProject(native, scope); + const selectedSeatId = sid && selectionBySession.has(sid) ? selectionBySession.get(sid) : null; + const models = sid && modelsBySession.has(sid) ? modelsBySession.get(sid) : null; + return buildPanelView({ project, selectedSeatId, models }); +} +function normalizeAction(event) { + const a = event && event.action; + if (a && typeof a === "object") return a; + const v = event && event.value; + if (v && typeof v === "object" && typeof v.type === "string") return v; + if (typeof a === "string") return Object.assign({ type: a }, v && typeof v === "object" ? v : {}); + return null; +} +async function handleEvent(native, scope, event) { + const sid = scope && typeof scope.sessionId === "string" ? scope.sessionId : null; + const action = normalizeAction(event); + if (!action || typeof action.type !== "string") return []; + switch (action.type) { + case "sansheng/select-seat": { + if (sid && action.seatId) selectionBySession.set(sid, action.seatId); + return [{ type: "refresh", id: PANEL_ID }]; + } + case "sansheng/select-model": { + if (sid && action.seatId) selectionBySession.set(sid, action.seatId); + return [{ type: "toast", text: "模型选择在原生面板暂未接持久化,请在 Web 端保存(需真机核验)" }]; + } + case "sansheng/enter-session": { + const bridged = native && native.dshGo; + const open = bridged && (bridged.openSession || bridged.navigate) || native && native.sansheng && native.sansheng.openSession; + if (typeof open === "function" && action.sessionId) { + try { + await open(action.sessionId); + return [{ type: "toast", text: "已请求打开会话" }]; + } catch (e) { + } + } + return [{ type: "toast", text: "原生 effect 暂不支持会话跳转,请从宿主会话列表进入(需真机核验)" }]; + } + default: + return []; + } +} +function makeDataProvider(native, dshGo) { + return function data(scope, emit) { + let cancelled = false; + const run = async () => { + if (typeof fetch !== "function") return; + const sid = scope && typeof scope.sessionId === "string" ? scope.sessionId : null; + if (!sid) return; + const post = async (endpoint, payload) => { + const res = await fetch("/api/sansheng", { + method: "POST", + credentials: "same-origin", + headers: { "content-type": "application/json" }, + body: JSON.stringify({ endpoint, payload: payload == null ? null : payload }) + }); + if (!res.ok) throw new Error("HTTP " + res.status); + const r = await res.json(); + if (!r || r.ok !== true) throw new Error(r && r.error && r.error.message || "request failed"); + return r.value; + }; + const list = await post("list"); + const projects = list && Array.isArray(list.projects) ? list.projects : []; + for (const meta of projects) { + const value = await post("project", { projectId: meta.id }); + const project = value && value.project ? value.project : value; + cacheProject(project); + const seats = project && project.seats; + const found = Array.isArray(seats) ? seats.some((s) => s && s.sessionId === sid) : seats && Object.values(seats).some((s) => s && s.sessionId === sid); + if (found) { + if (!cancelled) { + try { + emit({ project }); + } catch (e) { + } + try { + if (dshGo && typeof dshGo.refresh === "function") dshGo.refresh(PANEL_ID, scope); + } catch (e) { + } + } + return; + } + } + }; + run().catch(() => { + }); + return () => { + cancelled = true; + }; + }; +} +function install(ctx) { + if (!ctx || typeof ctx.inject !== "function") return () => { + }; + return ctx.inject(["dshGo", "sessions"], (native) => { + const dshGo = native && native.dshGo; + if (!dshGo || typeof dshGo.panel !== "function") return () => { + }; + const disposers = []; + try { + const offPanel = native.dshGo.panel(PANEL_ID, { + view: (scope, caps) => makeView(native, scope), + data: makeDataProvider(native, native.dshGo) + }); + if (typeof offPanel === "function") disposers.push(offPanel); + } catch (e) { + } + if (typeof native.dshGo.on === "function") { + try { + const offOn = native.dshGo.on(PANEL_ID, (scope, event) => handleEvent(native, scope, event)); + if (typeof offOn === "function") disposers.push(offOn); + } catch (e) { + } + } + return () => { + for (const off of disposers) { + try { + off(); + } catch (e) { + } + } + }; + }); +} +var native_default = { install }; + +// src/client/index.js +var import_react = require("react"); +var import_react_dom = require("react-dom"); +var inject = ["sessions", "uiWorkspace", "uiConversation", "slots", "theme", "layout"]; +var PLUGIN_ID = "dsh-sansheng"; +var TAB_KIND = "sansheng-workbench"; +var TAB_TYPE_ID = "dsh-sansheng:workbench"; +function installStyles(doc, tag, text) { + if (!doc || !doc.head) return null; + const style = doc.createElement("style"); + style.dataset.plugin = PLUGIN_ID; + style.dataset.sansheng = tag; + style.textContent = text; + doc.head.appendChild(style); + return style; +} +function svgWrap(children, props) { + return (0, import_react.createElement)("svg", { + viewBox: "0 0 24 24", + width: 16, + height: 16, + fill: "none", + stroke: "currentColor", + strokeWidth: 1.6, + strokeLinecap: "round", + strokeLinejoin: "round", + "aria-hidden": "true", + ...props || {} + }, children); +} +var TreeIcon = (props) => svgWrap([ + (0, import_react.createElement)("rect", { key: "a", x: 9, y: 2, width: 6, height: 5, rx: 1 }), + (0, import_react.createElement)("path", { key: "b", d: "M12 7v5M5 16v-4h14v4" }), + (0, import_react.createElement)("rect", { key: "c", x: 2, y: 16, width: 6, height: 5, rx: 1 }), + (0, import_react.createElement)("rect", { key: "d", x: 16, y: 16, width: 6, height: 5, rx: 1 }) +], props); +var CloseIcon = (props) => svgWrap([(0, import_react.createElement)("path", { key: "p", d: "m6 6 12 12M6 18 18 6" })], props); +var FolderIcon = (props) => svgWrap([(0, import_react.createElement)("path", { key: "p", d: "M3 7V5a2 2 0 0 1 2-2h5l2 3h7a2 2 0 0 1 2 2v11H3Z" })], props); +var GearIcon = (props) => svgWrap([ + (0, import_react.createElement)("path", { key: "a", d: "M4 6h16M4 12h16M4 18h16" }), + (0, import_react.createElement)("circle", { key: "b", cx: 9, cy: 6, r: 2 }), + (0, import_react.createElement)("circle", { key: "c", cx: 16, cy: 12, r: 2 }), + (0, import_react.createElement)("circle", { key: "d", cx: 8, cy: 18, r: 2 }) +], props); +var ChevronIcon = (props) => (0, import_react.createElement)("svg", { + viewBox: "0 0 24 24", + width: 14, + height: 14, + fill: "none", + stroke: "currentColor", + strokeWidth: 1.6, + strokeLinecap: "round", + strokeLinejoin: "round", + className: "ssw-chevron", + "aria-hidden": "true" +}, (0, import_react.createElement)("path", { d: "m6 9 6 6 6-6" })); +function isFn(value) { + return typeof value === "function"; +} +function safeCall(obj, name) { + try { + if (!obj || !isFn(obj[name])) return void 0; + return obj[name](); + } catch { + return void 0; + } +} +function snapshotOf(obj) { + if (!obj) return void 0; + if (isFn(obj.getSnapshot)) { + try { + return obj.getSnapshot(); + } catch { + return void 0; + } + } + return obj; +} +function apply(ctx) { + if (typeof document !== "undefined") installStyles(document, "workbench", CSS); + const get = (name) => { + try { + return ctx.get(name); + } catch { + return void 0; + } + }; + function workspaceItems() { + const fromWorkspaces = snapshotOf(get("workspaces")?.list)?.items; + if (Array.isArray(fromWorkspaces)) return fromWorkspaces; + const fromUi = snapshotOf(get("uiWorkspace")?.workspaces)?.items; + if (Array.isArray(fromUi)) return fromUi; + return []; + } + function normalizeWorkspace(item) { + if (!item || typeof item !== "object") return null; + const workspaceId = item.workspaceId ?? item.id ?? null; + if (typeof workspaceId !== "string" || !workspaceId) return null; + return { + workspaceId, + name: typeof item.name === "string" ? item.name : typeof item.title === "string" ? item.title : void 0, + path: typeof item.path === "string" ? item.path : void 0 + }; + } + function currentSessionId() { + const snap = snapshotOf(get("sessions")?.list) ?? snapshotOf(get("sessions")); + if (!snap || typeof snap !== "object") return null; + for (const key of ["activeId", "currentId", "selectedId"]) { + if (typeof snap[key] === "string" && snap[key]) return snap[key]; + } + if (snap.byId && typeof snap.byId === "object") { + const main = Object.values(snap.byId).find((session) => (session?.retainedBy?.mainView ?? 0) > 0); + if (main && typeof main.id === "string") return main.id; + } + return null; + } + function currentWorkspaceId() { + const candidates = []; + for (const holder of [get("workspaces"), get("uiWorkspace")]) { + if (!holder) continue; + for (const key of ["currentWorkspaceId", "currentId", "activeId"]) { + if (isFn(holder[key])) candidates.push(safeCall(holder, key)); + else if (typeof holder[key] === "string") candidates.push(holder[key]); + } + for (const key of ["current", "active", "selected", "currentWorkspace"]) { + const value = holder[key]; + const snap = snapshotOf(value); + if (snap && typeof snap === "object") candidates.push(snap.workspaceId ?? snap.id); + else if (typeof value === "string") candidates.push(value); + } + } + const sessionId = currentSessionId(); + if (sessionId) { + const owner = workspaceItems().find((item) => Array.isArray(item.sessionIds) && item.sessionIds.includes(sessionId)); + if (owner) candidates.push(owner.workspaceId ?? owner.id); + } + return candidates.find((id) => typeof id === "string" && id) ?? null; + } + function currentWorkspace() { + const items = workspaceItems().map(normalizeWorkspace).filter(Boolean); + const id = currentWorkspaceId(); + if (id) { + const hit = items.find((item) => item.workspaceId === id); + return hit || { workspaceId: id, name: void 0, path: void 0 }; + } + if (items.length === 1) return items[0]; + return null; + } + function seatRecordOf(view, id) { + const seats = view && view.project ? view.project.seats : null; + if (Array.isArray(seats)) return seats.find((seat) => seat && seat.id === id) || null; + if (seats && typeof seats === "object") return seats[id] || null; + return null; + } + function navigateToSession(sessionId) { + if (!sessionId) return false; + const attempts = []; + const ui = get("uiWorkspace"); + if (ui) { + if (isFn(ui.openSession)) attempts.push(() => ui.openSession(sessionId)); + if (isFn(ui.open)) attempts.push(() => ui.open(sessionId)); + } + const sessions = get("sessions"); + if (sessions) { + if (isFn(sessions.open)) attempts.push(() => sessions.open(sessionId)); + if (isFn(sessions.openSession)) attempts.push(() => sessions.openSession(sessionId)); + if (isFn(sessions.select)) attempts.push(() => sessions.select(sessionId)); + } + for (const name of ["navigation", "navigator", "router"]) { + const svc = get(name); + if (!svc) continue; + if (isFn(svc.openSession)) attempts.push(() => svc.openSession(sessionId)); + if (isFn(svc.navigate)) attempts.push(() => svc.navigate({ sessionId })); + if (isFn(svc.open)) attempts.push(() => svc.open(sessionId)); + } + for (const run of attempts) { + try { + const result = run(); + if (result && isFn(result.then)) result.catch(() => { + }); + return true; + } catch { + } + } + console.warn("[sansheng] 未找到可用的会话导航接口,仅发出 navigate 意图:", sessionId); + try { + if (typeof window !== "undefined") { + window.dispatchEvent(new CustomEvent("sansheng:navigate", { detail: { sessionId } })); + } + } catch { + } + return false; + } + function ensureRightTab() { + const tabs = get("sidebarRightTabs"); + return !!(tabs && isFn(tabs.get) && tabs.get(TAB_KIND)); + } + function tryOpenRightTab() { + const right = get("sidebarRight"); + if (!right || !isFn(right.openTab)) return false; + if (!ensureRightTab()) return false; + try { + right.openTab(TAB_KIND); + return true; + } catch (error) { + console.warn("[sansheng] 打开右侧标签失败,改用浮动面板:", error && error.message ? error.message : error); + return false; + } + } + function SanshengTabBody() { + return (0, import_react.createElement)("div", { className: "ssw-tab-body" }, (0, import_react.createElement)(SanshengWorkbench, {})); + } + function SanshengTabTitle() { + return (0, import_react.createElement)("span", { className: "ssw-tab-title" }, "三省六部"); + } + function registerRightTabType() { + try { + if (!isFn(ctx.inject)) return; + ctx.inject(["sidebarRightTabs"], (injected) => { + const tabs = injected.get("sidebarRightTabs"); + if (!tabs || !isFn(tabs.register)) return; + let disposeType = null, disposeBody = null, disposeTitle = null; + try { + disposeType = tabs.register({ id: TAB_TYPE_ID, kind: TAB_KIND, keepMounted: true, priority: "extension", title: () => "三省六部" }); + disposeBody = ctx.slots.inject("sidebar.right.pane.tab", () => ctx.slots.register({ + name: "sidebar.right.pane.tab", + key: TAB_TYPE_ID, + inject: (sessionId) => ({ sessionId }) + }, SanshengTabBody)); + disposeTitle = ctx.slots.inject("sidebar.right.pane.tab.title", () => ctx.slots.register({ + name: "sidebar.right.pane.tab.title", + key: TAB_TYPE_ID, + inject: (sessionId) => ({ sessionId }) + }, SanshengTabTitle)); + } catch (error) { + console.warn("[sansheng] 注册右侧标签失败:", error && error.message ? error.message : error); + try { + disposeBody && disposeBody(); + } catch { + } + try { + disposeTitle && disposeTitle(); + } catch { + } + try { + disposeType && disposeType(); + } catch { + } + return; + } + return () => { + try { + disposeBody && disposeBody(); + } catch { + } + try { + disposeTitle && disposeTitle(); + } catch { + } + try { + disposeType && disposeType(); + } catch { + } + }; + }); + } catch (error) { + console.warn("[sansheng] 注册右侧标签失败:", error && error.message ? error.message : error); + } + } + function SanshengWorkbench(props) { + const onClose = props && props.onClose ? props.onClose : null; + const [phase, setPhase] = (0, import_react.useState)("loading"); + const [error, setError] = (0, import_react.useState)(null); + const [notice, setNotice] = (0, import_react.useState)(null); + const [view, setView] = (0, import_react.useState)(null); + const [models, setModels] = (0, import_react.useState)(null); + const [selectedSeatId, setSelectedSeatId] = (0, import_react.useState)(SEAT_IDS[0]); + const [draft, setDraft] = (0, import_react.useState)({}); + const [busy, setBusy] = (0, import_react.useState)(false); + const [configOpen, setConfigOpen] = (0, import_react.useState)(false); + const [reportOpen, setReportOpen] = (0, import_react.useState)(false); + const alive = (0, import_react.useRef)(true); + (0, import_react.useEffect)(() => () => { + alive.current = false; + }, []); + const loadProject = (0, import_react.useCallback)(async () => { + setPhase("loading"); + setError(null); + setNotice(null); + const workspace = currentWorkspace(); + if (!workspace) { + setPhase("no-workspace"); + return; + } + try { + const projectView = await request("open", { + workspaceId: workspace.workspaceId, + name: workspace.name, + path: workspace.path + }); + let modelCatalog = null; + try { + modelCatalog = await request("models"); + } catch (modelError) { + console.warn("[sansheng] 模型目录加载失败:", modelError && modelError.message ? modelError.message : modelError); + } + if (!alive.current) return; + setView(projectView); + setModels(modelCatalog); + setPhase("ready"); + } catch (loadError) { + if (!alive.current) return; + setError(loadError && loadError.message ? loadError.message : "加载失败"); + setPhase("error"); + } + }, []); + (0, import_react.useEffect)(() => { + void loadProject(); + }, [loadProject]); + const wb = buildWorkbenchView(view, { selectedSeatId, models, draft }); + const seatById = (0, import_react.useMemo)(() => { + const map = {}; + for (const seat of wb.seats) map[seat.id] = seat; + return map; + }, [wb.seats]); + function pickSeat(id) { + if (!id) return; + if (id !== selectedSeatId) { + setSelectedSeatId(id); + setConfigOpen(false); + } + const seat = seatById[id]; + if (wb.ready && seat && seat.status === "bound") { + const rec = seatRecordOf(view, id); + if (rec && rec.sessionId) { + navigateToSession(rec.sessionId); + setNotice("已切换到" + seat.name + "会话"); + return; + } + } + if (wb.ready && seat && seat.status !== "bound") setNotice("该席尚未绑定会话,先启用或重试启用"); + } + function setModelValue(value) { + setDraft((prev) => updateDraft(prev, selectedSeatId, { modelValue: value })); + } + function setInstructions(value) { + setDraft((prev) => updateDraft(prev, selectedSeatId, { instructions: value })); + } + async function enableSeats() { + const projectId = view && view.project ? view.project.id : null; + if (!projectId) return; + setBusy(true); + setError(null); + setNotice("正在启用十席…"); + try { + const next = await request("enable", { projectId }); + if (!alive.current) return; + setView(next); + setNotice("十席已启用(建立独立会话,不自动运行模型)"); + } catch (enableError) { + if (alive.current) setError(enableError && enableError.message ? enableError.message : "启用失败"); + } finally { + if (alive.current) setBusy(false); + } + } + async function saveConfig() { + const projectId = view && view.project ? view.project.id : null; + if (!projectId) return; + const seatId = wb.selected.id; + const value = wb.selected.modelValue; + if (!value) { + setNotice("请先为当前角色选择模型"); + return; + } + const option = findModelOption(wb.selected.modelOptions, value); + const model = option ? option.reasoningEffort ? { provider: option.provider, model: option.model, reasoningEffort: option.reasoningEffort } : { provider: option.provider, model: option.model } : null; + setBusy(true); + setError(null); + setNotice("保存中…"); + try { + await request("configure", { projectId, seatId, model, instructions: wb.selected.instructions }); + const next = await request("project", { projectId }); + if (!alive.current) return; + setView(next); + setDraft((prev) => clearDraft(prev, seatId)); + setNotice("已保存"); + } catch (saveError) { + if (alive.current) setError(saveError && saveError.message ? saveError.message : "保存失败"); + } finally { + if (alive.current) setBusy(false); + } + } + const seatCard = (seat) => (0, import_react.createElement)( + "button", + { + key: seat.id, + type: "button", + className: "ssw-seat", + "aria-pressed": seat.selected ? "true" : "false", + title: seat.name + " · " + seat.duty + "(" + seat.statusLabel + ")", + onClick: () => pickSeat(seat.id) + }, + (0, import_react.createElement)( + "span", + { className: "ssw-role-top" }, + (0, import_react.createElement)("span", { className: "ssw-role-name" }, seat.name), + (0, import_react.createElement)("span", { className: "ssw-dot", "data-status": seat.status, "aria-hidden": "true" }) + ), + (0, import_react.createElement)("span", { className: "ssw-role-duty" }, seat.duty) + ); + const pickList = (ids) => ids.map((id) => seatById[id]).filter(Boolean); + const tree = (0, import_react.createElement)( + "section", + { className: "ssw-tree", "aria-label": "切换角色" }, + (0, import_react.createElement)("div", { className: "ssw-lead" }, pickList(wb.groups.lead).map(seatCard)), + (0, import_react.createElement)( + "div", + { className: "ssw-sansheng" }, + (0, import_react.createElement)("span", { className: "ssw-group-label" }, "三省"), + (0, import_react.createElement)("div", { className: "ssw-trio" }, pickList(wb.groups.sansheng).map(seatCard)) + ), + (0, import_react.createElement)( + "div", + { className: "ssw-ministries" }, + (0, import_react.createElement)("span", { className: "ssw-group-label" }, "六部 · 尚书统筹"), + (0, import_react.createElement)("div", { className: "ssw-six" }, pickList(wb.groups.liubu).map(seatCard)) + ) + ); + const head = (0, import_react.createElement)( + "header", + { className: "ssw-head" }, + (0, import_react.createElement)(TreeIcon), + (0, import_react.createElement)("strong", { className: "ssw-head-title" }, "工作台"), + onClose ? (0, import_react.createElement)("button", { type: "button", className: "ssw-icon-btn", onClick: onClose, "aria-label": "收起工作台" }, (0, import_react.createElement)(CloseIcon)) : null + ); + const projectInfo = (0, import_react.createElement)( + "div", + { className: "ssw-project" }, + (0, import_react.createElement)( + "div", + { className: "ssw-project-line" }, + (0, import_react.createElement)("span", { className: "ssw-eyebrow" }, (0, import_react.createElement)(FolderIcon), "当前项目"), + (0, import_react.createElement)("span", { className: "ssw-count" }, wb.project.seatCount + " 个角色 · " + wb.project.sessionCount + " 个会话") + ), + (0, import_react.createElement)("div", { className: "ssw-project-title" }, wb.projectTitle || "未命名项目") + ); + const enableBlock = !wb.ready ? (0, import_react.createElement)( + "div", + { className: "ssw-enable" }, + (0, import_react.createElement)("p", { className: "ssw-enable-note" }, "这个项目还没有启用十席。启用会建立十个独立会话,但不会自动运行模型。"), + (0, import_react.createElement)("button", { + type: "button", + className: "ssw-primary", + disabled: busy, + onClick: enableSeats + }, busy ? "正在启用…" : "启用此项目的十席") + ) : null; + const currentCard = (0, import_react.createElement)( + "section", + { className: "ssw-current" }, + (0, import_react.createElement)( + "div", + { className: "ssw-current-top" }, + (0, import_react.createElement)("strong", { className: "ssw-current-name" }, wb.selected.name), + (0, import_react.createElement)("span", { className: "ssw-current-label" }, "角色职责 · " + wb.selected.statusLabel) + ), + (0, import_react.createElement)("p", { className: "ssw-current-text" }, wb.selected.responsibility) + ); + const optionEls = wb.selected.modelOptions.map((option) => (0, import_react.createElement)("option", { key: option.value, value: option.value }, option.label)); + if (wb.selected.modelValue && !wb.selected.modelOptions.some((option) => option.value === wb.selected.modelValue)) { + optionEls.push((0, import_react.createElement)("option", { key: "__current__", value: wb.selected.modelValue }, wb.selected.modelLabel)); + } + const config = (0, import_react.createElement)( + "section", + { className: "ssw-config" }, + (0, import_react.createElement)( + "button", + { + type: "button", + className: "ssw-config-toggle", + "aria-expanded": configOpen ? "true" : "false", + onClick: () => setConfigOpen((value) => !value) + }, + (0, import_react.createElement)(GearIcon), + (0, import_react.createElement)("span", null, "配置" + wb.selected.name + (wb.selected.dirty ? " · 未保存" : "")), + (0, import_react.createElement)(ChevronIcon) + ), + configOpen ? (0, import_react.createElement)( + "div", + { className: "ssw-config-body" }, + (0, import_react.createElement)("label", { className: "ssw-label" }, "会话模型"), + (0, import_react.createElement)( + "select", + { + className: "ssw-field", + value: wb.selected.modelValue, + disabled: busy, + onChange: (event) => setModelValue(event.target.value) + }, + (0, import_react.createElement)("option", { value: "", disabled: true }, UNCHOSEN_MODEL_LABEL), + ...optionEls + ), + (0, import_react.createElement)("label", { className: "ssw-label" }, "角色补充说明"), + (0, import_react.createElement)("textarea", { + className: "ssw-field ssw-textarea", + rows: 4, + value: wb.selected.instructions, + disabled: busy, + placeholder: "补充该角色在当前项目中的工作要求", + onChange: (event) => setInstructions(event.target.value) + }), + (0, import_react.createElement)("p", { className: "ssw-scope-note" }, "每个角色是独立会话;模型与说明只影响当前项目当前角色,不改变宿主默认模型。"), + (0, import_react.createElement)( + "div", + { className: "ssw-save-row" }, + (0, import_react.createElement)("button", { type: "button", className: "ssw-primary", disabled: busy, onClick: saveConfig }, busy ? "保存中…" : "保存配置"), + wb.selected.dirty ? (0, import_react.createElement)("span", { className: "ssw-save-status" }, "有未保存修改") : null + ) + ) : null + ); + const report = (0, import_react.createElement)( + "section", + { className: "ssw-report" }, + (0, import_react.createElement)("button", { + type: "button", + className: "ssw-report-toggle", + "aria-expanded": reportOpen ? "true" : "false", + onClick: () => setReportOpen((value) => !value) + }, reportOpen ? "收起职责汇报" : "全部汇报职责"), + reportOpen ? (0, import_react.createElement)( + "div", + { className: "ssw-report-list" }, + SEAT_IDS.map((id) => { + const rec = seatRecordOf(view, id); + const m = rec && rec.model; + const modelLabel = m && m.model ? m.model + (m.reasoningEffort ? " · " + m.reasoningEffort : "") : "未选择模型"; + return (0, import_react.createElement)( + "div", + { key: id, className: "ssw-report-item", "data-seat": id }, + (0, import_react.createElement)( + "div", + { className: "ssw-report-head" }, + (0, import_react.createElement)("strong", null, SEATS[id].label), + (0, import_react.createElement)("span", null, SEATS[id].duty) + ), + (0, import_react.createElement)("p", { className: "ssw-report-model" }, "模型:" + modelLabel), + (0, import_react.createElement)("p", { className: "ssw-report-text" }, SEATS[id].responsibility) + ); + }) + ) : null + ); + const statusEl = error ? (0, import_react.createElement)("p", { className: "ssw-error", role: "alert" }, error) : notice ? (0, import_react.createElement)("p", { className: "ssw-notice", role: "status" }, notice) : null; + let body; + if (phase === "loading") body = (0, import_react.createElement)("div", { className: "ssw-loading" }, "正在加载工作台…"); + else if (phase === "no-workspace") body = (0, import_react.createElement)( + "div", + { className: "ssw-empty" }, + (0, import_react.createElement)("p", null, "先从左侧选择一个项目"), + (0, import_react.createElement)("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 || "加载失败"), + (0, import_react.createElement)("button", { type: "button", className: "ssw-primary", onClick: loadProject }, "重试") + ); + else body = (0, import_react.createElement)(import_react.Fragment, null, projectInfo, enableBlock, tree, report, currentCard, config, statusEl); + return (0, import_react.createElement)("div", { className: "ssw-root ssw-scope" }, head, body); + } + function SanshengEntry(props) { + const compact = !!(props && props.compact); + const [floating, setFloating] = (0, import_react.useState)(false); + const onClick = () => { + if (tryOpenRightTab()) { + setFloating(false); + return; + } + setFloating((value) => !value); + }; + let panel = null; + if (floating) { + const card = (0, import_react.createElement)( + "div", + { className: "ssw-float", role: "dialog", "aria-label": "三省六部工作台" }, + (0, import_react.createElement)(SanshengWorkbench, { onClose: () => setFloating(false) }) + ); + const canPortal = typeof document !== "undefined" && document.body && isFn(import_react_dom.createPortal); + panel = canPortal ? (0, import_react_dom.createPortal)(card, document.body) : card; + } + return (0, import_react.createElement)( + import_react.Fragment, + null, + (0, import_react.createElement)( + "button", + { + type: "button", + className: compact ? "ssw-entry ssw-entry-compact" : "ssw-entry", + title: "三省六部", + "aria-expanded": floating ? "true" : "false", + onClick + }, + (0, import_react.createElement)(TreeIcon), + (0, import_react.createElement)("span", { className: "ssw-entry-label" }, "三省六部") + ), + panel + ); + } + function SanshengSessionAction(props) { + const children = props && props.children; + return (0, import_react.createElement)(import_react.Fragment, null, children, (0, import_react.createElement)(SanshengEntry, { compact: true })); + } + try { + if (ctx.slots && isFn(ctx.slots.inject) && isFn(ctx.slots.register)) { + ctx.slots.inject("sidebar.session.action", () => ctx.slots.register({ + name: "sidebar.session.action", + id: "sansheng-entry" + }, SanshengSessionAction)); + } else { + console.warn("[sansheng] 宿主未提供 slots.inject / slots.register,无法注册侧栏入口"); + } + } catch (error) { + console.warn("[sansheng] 注册侧栏入口失败:", error && error.message ? error.message : error); + } + registerRightTabType(); + try { + install(ctx); + } catch (error) { + console.warn("[sansheng] 原生面板注册失败:", error && error.message ? error.message : error); + } +} +return Object.defineProperty({ ...module.exports }, Symbol.toStringTag, { value: 'Module' }) + }, +}) diff --git a/cordis.patch.yml b/cordis.patch.yml new file mode 100644 index 0000000..f4bff84 --- /dev/null +++ b/cordis.patch.yml @@ -0,0 +1,4 @@ +# 三省六部:挂到 DSH 宿主的三省六部工作台插件。 +- insert: + - id: sansheng + name: 'dsh-sansheng-liubu' diff --git a/index.js b/index.js new file mode 100644 index 0000000..e1aa966 --- /dev/null +++ b/index.js @@ -0,0 +1,46 @@ +// 三省六部宿主插件入口:只使用宿主公开注入服务,不 patch DSH,不写 profile 全局默认。 +import { SanshengStore } from './src/host/store.js' +import { createProvisioner } from './src/host/provision.js' +import { SanshengService } from './src/host/service.js' +import { createApiHandler } from './src/host/api.js' +import { installPromptSection } from './src/host/prompt.js' +import { sanshengStatePath } from './src/host/paths.js' +import { ROUTE } from './src/host/constants.js' + +export const name = 'sansheng' +export const inject = ['workspaceRegistry', 'sessionController', 'agents', 'llm', 'systemPrompt', 'connection'] + +export function apply(ctx, config = {}) { + const store = new SanshengStore( + typeof config.statePath === 'string' && config.statePath !== '' ? config.statePath : sanshengStatePath(config.home), + ) + // apply 必须同步返回(cordis 把异步/非函数返回值当非法 effect);状态在首次请求时惰性读入。 + void store.ensureLoaded().catch(error => { + console.warn(`sansheng: ${error?.message ?? error}`) + }) + + const host = { + workspaceRegistry: ctx.workspaceRegistry, + sessionController: ctx.sessionController, + agents: ctx.agents, + llm: ctx.llm, + } + const provisioner = createProvisioner({ store, host }) + const service = new SanshengService({ store, host, provisioner }) + const handle = createApiHandler(service) + + ctx.effect(() => installPromptSection(ctx, { store }), 'sansheng: prompt section') + + // 复用宿主共享 /api 通道;浏览器带会话 Cookie 认证。 + ctx.effect(() => ctx.connection.fetch.register({ + path: ROUTE, + methods: ['POST'], + requestBody: 'buffered', + fetch: async request => { + let body + try { body = await request.json() } catch { body = {} } + const result = await handle(String(body?.endpoint ?? ''), body?.payload) + return new Response(JSON.stringify(result), { status: 200, headers: { 'content-type': 'application/json' } }) + }, + }), 'sansheng: api route') +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..5353b89 --- /dev/null +++ b/package.json @@ -0,0 +1,52 @@ +{ + "name": "dsh-sansheng-liubu", + "version": "0.1.1", + "description": "三省六部:每个项目固定十席角色与独立会话的 DSH 插件(第一版)。", + "keywords": [ + "dsh-plugin", + "deepseek-harness", + "dsh", + "sansheng", + "multi-agent", + "agents" + ], + "license": "Apache-2.0", + "type": "module", + "main": "index.js", + "exports": { + ".": "./index.js", + "./client": "./client.js", + "./package.json": "./package.json" + }, + "files": [ + "index.js", + "client.js", + "src/", + "cordis.patch.yml", + "README.md" + ], + "scripts": { + "build": "node scripts/build-client.mjs", + "build:check": "node scripts/build-client.mjs --check", + "test": "node --test --test-timeout=120000 \"test/*.test.js\"" + }, + "peerDependencies": { + "@deepseek-ai/cordis": "*", + "@deepseek-ai/dsh-llm": "*", + "@deepseek-ai/dsh-web": "*" + }, + "dsh": { + "client": { + "platform": "web", + "inject": [ + "@deepseek-ai/dsh-client-ui-primitives" + ] + }, + "bundle": { + "patch": "./cordis.patch.yml" + } + }, + "devDependencies": { + "esbuild": "0.28.2" + } +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml new file mode 100644 index 0000000..676fa64 --- /dev/null +++ b/pnpm-lock.yaml @@ -0,0 +1,407 @@ +lockfileVersion: '9.0' + +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false + +importers: + + .: + dependencies: + '@deepseek-ai/cordis': + specifier: '*' + version: 4.1.0 + '@deepseek-ai/dsh-llm': + specifier: '*' + version: 0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)(@deepseek-ai/dsh-attachment@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)(@deepseek-ai/dsh-brand@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)(@deepseek-ai/dsh-invariants@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)))(@deepseek-ai/dsh-invariants@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)))(@deepseek-ai/dsh-brand@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)(@deepseek-ai/dsh-invariants@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)))(@deepseek-ai/dsh-invariants@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0))(@deepseek-ai/dsh-timeout@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)(@deepseek-ai/dsh-invariants@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0))) + '@deepseek-ai/dsh-web': + specifier: '*' + version: 0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)(@deepseek-ai/dsh-invariants@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0))(@deepseek-ai/dsh-llm@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)(@deepseek-ai/dsh-attachment@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)(@deepseek-ai/dsh-brand@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)(@deepseek-ai/dsh-invariants@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)))(@deepseek-ai/dsh-invariants@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)))(@deepseek-ai/dsh-brand@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)(@deepseek-ai/dsh-invariants@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)))(@deepseek-ai/dsh-invariants@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0))(@deepseek-ai/dsh-timeout@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)(@deepseek-ai/dsh-invariants@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)))) + devDependencies: + esbuild: + specifier: 0.28.2 + version: 0.28.2 + +packages: + + '@deepseek-ai/cordis@4.1.0': + resolution: {integrity: sha512-CJrjNyBkKn1SfvBQUcgFYKFnLjS+uKrhdMsbHU60xabvi12d+xQ+IQSNlME5Z+B+4Zi6n4BDknKY94tEPeo47w==} + hasBin: true + peerDependencies: + '@deepseek-ai/cordis-plugin-include': ~1.1.0 + '@deepseek-ai/cordis-plugin-loader': ~1.1.0 + peerDependenciesMeta: + '@deepseek-ai/cordis-plugin-include': + optional: true + '@deepseek-ai/cordis-plugin-loader': + optional: true + + '@deepseek-ai/cosmokit@1.9.0': + resolution: {integrity: sha512-5O1S53mZiJyZYcvxxD0Qv1EY7qFPSxbGyD8CbVK6gw7W9FvcXZj2YIX1ZkOqyQQ3Xt2rFkZDHJv0+V3Zmmp8CA==} + + '@deepseek-ai/dsh-attachment@0.0.1-rc.1': + resolution: {integrity: sha512-zBBw6h+YKOf7U8uEZezbFUjLsA8VU1GfCIUonAZHG2hWDWhWbrGaoO9fL8KyncEDSWMLMoIoGo+ZxDEPVJZYOA==} + peerDependencies: + '@deepseek-ai/cordis': ^4.0.1-rc.1 + '@deepseek-ai/dsh-brand': ^0.0.1-rc.1 + '@deepseek-ai/dsh-invariants': ^0.0.1-rc.1 + + '@deepseek-ai/dsh-brand@0.0.1-rc.1': + resolution: {integrity: sha512-XhwNAugG/baCVA+BMMvjihYi9XMLcDUew3G63i+ATWIZCvpx8CghbgcV93DEeMH2sqhNuQAssmHgXkpRld3gyQ==} + peerDependencies: + '@deepseek-ai/cordis': ^4.0.1-rc.1 + '@deepseek-ai/dsh-invariants': ^0.0.1-rc.1 + + '@deepseek-ai/dsh-invariants@0.0.1-rc.1': + resolution: {integrity: sha512-ZoGCGColviu3Tkdnv9hMkgBE4eg0hAz5GXR/knqRf7mJUeBlTCya2dIckYlqekYmp5L+1AeWxf9j+Lv1YRcvXw==} + peerDependencies: + '@deepseek-ai/cordis': ^4.0.1-rc.1 + + '@deepseek-ai/dsh-llm@0.0.1-rc.1': + resolution: {integrity: sha512-mRJj07IQNfRReGrhpMpL8AONiYKqfwzxvepg/ut9Wkj8oH2BuoftPS4cMnnXFFCUlYql04/sezwDLriYks/bmw==} + peerDependencies: + '@deepseek-ai/cordis': ^4.0.1-rc.1 + '@deepseek-ai/dsh-attachment': ^0.0.1-rc.1 + '@deepseek-ai/dsh-brand': ^0.0.1-rc.1 + '@deepseek-ai/dsh-invariants': ^0.0.1-rc.1 + '@deepseek-ai/dsh-timeout': ^0.0.1-rc.1 + + '@deepseek-ai/dsh-timeout@0.0.1-rc.1': + resolution: {integrity: sha512-lIMhY/JqA+eLpXXUN33xA7mlAYeHTDTWfcJ3CmEtplvGnvpDAHQ6oPeFs9JtWcfKbuNDZFMNutyhD0qoRkFQeg==} + peerDependencies: + '@deepseek-ai/cordis': ^4.0.1-rc.1 + '@deepseek-ai/dsh-invariants': ^0.0.1-rc.1 + + '@deepseek-ai/dsh-web@0.0.1-rc.1': + resolution: {integrity: sha512-kbfr8aPtbsO9XOYqbdy39HwLPlVDH3GWjg9J2cJge5jgGPfN0lGlh5hcj4wvHxUEhGOZF+vieR/U8NmzeaeZMw==} + peerDependencies: + '@deepseek-ai/cordis': ^4.0.1-rc.1 + '@deepseek-ai/dsh-invariants': ^0.0.1-rc.1 + '@deepseek-ai/dsh-llm': ^0.0.1-rc.1 + + '@deepseek-ai/schemastery@3.19.0': + resolution: {integrity: sha512-bDXoYQa7ghAhmdYD5VPlzKxEzJV/aKkz5l4V5h1u06z8GAPN1ROewSjvR9WiXhpa52E9fng8lpH5QdCRIQgnyQ==} + + '@esbuild/aix-ppc64@0.28.2': + resolution: {integrity: sha512-XExcO+dvLKvVtNTibSTBej1NCAbaGhWn9Ww1ZPx80qsahhPFe/8jgWP0IchNe0F3HwkU7n8ejhH8bjonqht8mQ==} + engines: {node: '>=18'} + cpu: [ppc64] + os: [aix] + + '@esbuild/android-arm64@0.28.2': + resolution: {integrity: sha512-5YfKeeI8qWfBZIX+u2xZC3Zlb3Os/gLS2sbEKM+I4ZOcsWmHS2WLysCcQZDAFRslDUU5Oiq44gf6PYN1vGwG5A==} + engines: {node: '>=18'} + cpu: [arm64] + os: [android] + + '@esbuild/android-arm@0.28.2': + resolution: {integrity: sha512-kXXoiPVVGQcnIYGOeaovwOURpniDBpSq4A03qkQ+BMQqtGG6HYap3xne9C1O1yo4TR3qxlCX5IqqmX6fFo2Lqg==} + engines: {node: '>=18'} + cpu: [arm] + os: [android] + + '@esbuild/android-x64@0.28.2': + resolution: {integrity: sha512-O387ite7SzUyCcy3JQX4P4bLtEA7bLLkx+esve5JHnyYfNTxcVpXZo9jhdB0lTKN44gztELTdU7nS8Nr16Fs1Q==} + engines: {node: '>=18'} + cpu: [x64] + os: [android] + + '@esbuild/darwin-arm64@0.28.2': + resolution: {integrity: sha512-n4KqkOQrraxHJcgjM1RvwbigfQKIKJVpM7xp+KsxiyUSrRdIXnt73VhrPAx0fV44hgfmIVKjxMN9J1t5jySVkw==} + engines: {node: '>=18'} + cpu: [arm64] + os: [darwin] + + '@esbuild/darwin-x64@0.28.2': + resolution: {integrity: sha512-uq6suIWYP37qzGddBKPw5QEQPi6HiLGsO7UmkpfyaYNQ3D+rN6w6WfwH+nuqcGXWvawGwxOEroO4YGnFh95azw==} + engines: {node: '>=18'} + cpu: [x64] + os: [darwin] + + '@esbuild/freebsd-arm64@0.28.2': + resolution: {integrity: sha512-n+I0BTSRIoy+d6RPKnEVwql5UwBJolytvY4mAOIEJorKlqgPII8ix6slVVrfZ5Tnj7glIZvloylbB/EJPMWEXw==} + engines: {node: '>=18'} + cpu: [arm64] + os: [freebsd] + + '@esbuild/freebsd-x64@0.28.2': + resolution: {integrity: sha512-78XJTJkvPs0kz2w61301PJjXl4g7q3JqiYMZ/M/yVI73EHBrCRTgkhu9oqG7vPqq+a/yadEW8aD+agKlk5xrmg==} + engines: {node: '>=18'} + cpu: [x64] + os: [freebsd] + + '@esbuild/linux-arm64@0.28.2': + resolution: {integrity: sha512-pW4AC0P3it8c7do9MVM4p51FzHzdM/TZrerurgRcHJ2WTa1VQ1CIq18xncfpBJw4ojkiZZrKW2yIBWBP92j6Ug==} + engines: {node: '>=18'} + cpu: [arm64] + os: [linux] + + '@esbuild/linux-arm@0.28.2': + resolution: {integrity: sha512-XlDnu2q5yoqems+xay6wSAcg9DDD7K9RLKZEBOMZm3ckNpJBvOX20tSfby8KfrrhINDyv9V2YVZKY/SpoGJI8w==} + engines: {node: '>=18'} + cpu: [arm] + os: [linux] + + '@esbuild/linux-ia32@0.28.2': + resolution: {integrity: sha512-CYbnj78HsIeA+DhgUKgFCfvNsTHFhMMrinUrMZpDXJXKN8T3XViTZ/+wtHeVxEWY8ewSzTFN+nRmSwO2tZaLUQ==} + engines: {node: '>=18'} + cpu: [ia32] + os: [linux] + + '@esbuild/linux-loong64@0.28.2': + resolution: {integrity: sha512-buwkd8nsph4R+ajRvw0qM5Hja/TXQow3ptzWO2EbG/cqcIkHloRrdlBtQlshyYGTNFvfkfJ5tpPLVkY4DtsPfQ==} + engines: {node: '>=18'} + cpu: [loong64] + os: [linux] + + '@esbuild/linux-mips64el@0.28.2': + resolution: {integrity: sha512-ZVykbDyk7519VwiNb9Lcj9m8XM6v5V9uKPvrEMkkEedVewf+0itkhahp4HDpgERXhwLRpWFypsGbG/J8s0QjJA==} + engines: {node: '>=18'} + cpu: [mips64el] + os: [linux] + + '@esbuild/linux-ppc64@0.28.2': + resolution: {integrity: sha512-CAXl+Dtd9UUuJd8pKKdwh6MLm3MUMiqMPmhZ3tTSXPqfyQ3vDl6R5hZdZ/kYojK4ofXtdfSv1tFq8XzWx3heNQ==} + engines: {node: '>=18'} + cpu: [ppc64] + os: [linux] + + '@esbuild/linux-riscv64@0.28.2': + resolution: {integrity: sha512-GeXCej4IQtU1B+QlDV8W/RRvbzI3O/Stss+/bCXv4lZls5WGRtu2a+3JkA3i4qIUlMXpcHebWpF8AkJhATowuA==} + engines: {node: '>=18'} + cpu: [riscv64] + os: [linux] + + '@esbuild/linux-s390x@0.28.2': + resolution: {integrity: sha512-3H1weTYZPxt/WOhByszQZybS9w5lKzUn1FDMsgEChbHWQwHYQQRfBxgCcZvPhjHfKyJjIievvMmEUawJrdY9Dg==} + engines: {node: '>=18'} + cpu: [s390x] + os: [linux] + + '@esbuild/linux-x64@0.28.2': + resolution: {integrity: sha512-4xTZr1FUmSoQW4XIWmit3tzQrUTZM+N3P0XV8xROKYF50XfI7xeO90+1bZvNwxIufQ9hDQVRJH5YhgPVF8A/HQ==} + engines: {node: '>=18'} + cpu: [x64] + os: [linux] + + '@esbuild/netbsd-arm64@0.28.2': + resolution: {integrity: sha512-sSATRjPeDBg3pdgHoQfoYBob11Kk1FGa9lui5RIHZCoCkJa9QKlvl3/vKz2usCmYYjs7ymJR/2Nnsqe+Hjt5nw==} + engines: {node: '>=18'} + cpu: [arm64] + os: [netbsd] + + '@esbuild/netbsd-x64@0.28.2': + resolution: {integrity: sha512-lqnzCV+mM0gIADaKihiCg6ifgfU2L3h5E33rNQBN1Y4MaVGnzryzmvvf7UHxprpQdE8hpqLolJ9Rl+SkIRDpyw==} + engines: {node: '>=18'} + cpu: [x64] + os: [netbsd] + + '@esbuild/openbsd-arm64@0.28.2': + resolution: {integrity: sha512-AL2qJILH7lNjrDmCQDvdxMfAUIv8KMNZOvrwAQ8i8//ntL9FflhOyMJ8OZSMBb8/AWXe3/5v5S20y3zCoZWKoQ==} + engines: {node: '>=18'} + cpu: [arm64] + os: [openbsd] + + '@esbuild/openbsd-x64@0.28.2': + resolution: {integrity: sha512-QtiuPytchRyC4rwUKhexJdQKvDuZ6hWloi3igqPQNUJCS1/v9EiO3UTOXR6A3FoMo4fnAKbWJdqaIwhOzh8qEw==} + engines: {node: '>=18'} + cpu: [x64] + os: [openbsd] + + '@esbuild/openharmony-arm64@0.28.2': + resolution: {integrity: sha512-WkhYDmpTjLvGlScA1rwjRUmhl4k8oXR3cIbtqWmELgU/dFeHHlEllxDvdWcNJV9rbzCexB5vz8gtNewWLgCT7Q==} + engines: {node: '>=18'} + cpu: [arm64] + os: [openharmony] + + '@esbuild/sunos-x64@0.28.2': + resolution: {integrity: sha512-GPMSkTOtMnv2U2F8gxe4Io6qmVs+YKyp832Etqqxr0hFngmXQ3rzwytelm3GIn7T4VviRUlf3sOgBOiTdvaf7g==} + engines: {node: '>=18'} + cpu: [x64] + os: [sunos] + + '@esbuild/win32-arm64@0.28.2': + resolution: {integrity: sha512-PIhhEkE9uPBleRBrQEJpUn7MBnibZzbGzYWPmY3x+YoVg/95zbjB4CxPPOQ8l5tYYM4mMaCthF8/1DIfBQQyWQ==} + engines: {node: '>=18'} + cpu: [arm64] + os: [win32] + + '@esbuild/win32-ia32@0.28.2': + resolution: {integrity: sha512-YmJbfTlvU7Sdn9BB+4PRES4oB6pxgS37MAONj+hBr/cpXS1aBPKXxNnDbu+QCWPj0o9dgyxeq79g6c5P8KeuYA==} + engines: {node: '>=18'} + cpu: [ia32] + os: [win32] + + '@esbuild/win32-x64@0.28.2': + resolution: {integrity: sha512-5ebpxr3nWMzrL/rnUI755Jkuee0bHL/Gq0WTF9lvcpv73wAp5eu8MfBUgWK9bhWvZjj7yX8etf/8tI8Ney695g==} + engines: {node: '>=18'} + cpu: [x64] + os: [win32] + + '@standard-schema/spec@1.1.0': + resolution: {integrity: sha512-l2aFy5jALhniG5HgqrD6jXLi/rUWrKvqN/qJx6yoJsgKhblVd+iqqU4RCXavm/jPityDo5TCvKMnpjKnOriy0w==} + + esbuild@0.28.2: + resolution: {integrity: sha512-HKVLS8dvII+xoKW9kmqxbRKrnWEXfJJr/FZhhJmiqIB0e053QNYFqOBouTMO/k5sID4MvCiUCvv8b9M4h32wIA==} + engines: {node: '>=18'} + hasBin: true + +snapshots: + + '@deepseek-ai/cordis@4.1.0': + dependencies: + '@deepseek-ai/cosmokit': 1.9.0 + '@standard-schema/spec': 1.1.0 + + '@deepseek-ai/cosmokit@1.9.0': {} + + '@deepseek-ai/dsh-attachment@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)(@deepseek-ai/dsh-brand@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)(@deepseek-ai/dsh-invariants@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)))(@deepseek-ai/dsh-invariants@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0))': + dependencies: + '@deepseek-ai/cordis': 4.1.0 + '@deepseek-ai/dsh-brand': 0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)(@deepseek-ai/dsh-invariants@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)) + '@deepseek-ai/dsh-invariants': 0.0.1-rc.1(@deepseek-ai/cordis@4.1.0) + + '@deepseek-ai/dsh-brand@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)(@deepseek-ai/dsh-invariants@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0))': + dependencies: + '@deepseek-ai/cordis': 4.1.0 + '@deepseek-ai/dsh-invariants': 0.0.1-rc.1(@deepseek-ai/cordis@4.1.0) + + '@deepseek-ai/dsh-invariants@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)': + dependencies: + '@deepseek-ai/cordis': 4.1.0 + '@deepseek-ai/schemastery': 3.19.0 + + '@deepseek-ai/dsh-llm@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)(@deepseek-ai/dsh-attachment@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)(@deepseek-ai/dsh-brand@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)(@deepseek-ai/dsh-invariants@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)))(@deepseek-ai/dsh-invariants@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)))(@deepseek-ai/dsh-brand@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)(@deepseek-ai/dsh-invariants@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)))(@deepseek-ai/dsh-invariants@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0))(@deepseek-ai/dsh-timeout@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)(@deepseek-ai/dsh-invariants@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)))': + dependencies: + '@deepseek-ai/cordis': 4.1.0 + '@deepseek-ai/dsh-attachment': 0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)(@deepseek-ai/dsh-brand@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)(@deepseek-ai/dsh-invariants@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)))(@deepseek-ai/dsh-invariants@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)) + '@deepseek-ai/dsh-brand': 0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)(@deepseek-ai/dsh-invariants@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)) + '@deepseek-ai/dsh-invariants': 0.0.1-rc.1(@deepseek-ai/cordis@4.1.0) + '@deepseek-ai/dsh-timeout': 0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)(@deepseek-ai/dsh-invariants@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)) + '@deepseek-ai/schemastery': 3.19.0 + + '@deepseek-ai/dsh-timeout@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)(@deepseek-ai/dsh-invariants@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0))': + dependencies: + '@deepseek-ai/cordis': 4.1.0 + '@deepseek-ai/dsh-invariants': 0.0.1-rc.1(@deepseek-ai/cordis@4.1.0) + + '@deepseek-ai/dsh-web@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)(@deepseek-ai/dsh-invariants@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0))(@deepseek-ai/dsh-llm@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)(@deepseek-ai/dsh-attachment@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)(@deepseek-ai/dsh-brand@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)(@deepseek-ai/dsh-invariants@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)))(@deepseek-ai/dsh-invariants@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)))(@deepseek-ai/dsh-brand@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)(@deepseek-ai/dsh-invariants@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)))(@deepseek-ai/dsh-invariants@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0))(@deepseek-ai/dsh-timeout@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)(@deepseek-ai/dsh-invariants@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0))))': + dependencies: + '@deepseek-ai/cordis': 4.1.0 + '@deepseek-ai/dsh-invariants': 0.0.1-rc.1(@deepseek-ai/cordis@4.1.0) + '@deepseek-ai/dsh-llm': 0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)(@deepseek-ai/dsh-attachment@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)(@deepseek-ai/dsh-brand@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)(@deepseek-ai/dsh-invariants@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)))(@deepseek-ai/dsh-invariants@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)))(@deepseek-ai/dsh-brand@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)(@deepseek-ai/dsh-invariants@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)))(@deepseek-ai/dsh-invariants@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0))(@deepseek-ai/dsh-timeout@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0)(@deepseek-ai/dsh-invariants@0.0.1-rc.1(@deepseek-ai/cordis@4.1.0))) + '@deepseek-ai/schemastery': 3.19.0 + + '@deepseek-ai/schemastery@3.19.0': + dependencies: + '@deepseek-ai/cosmokit': 1.9.0 + '@standard-schema/spec': 1.1.0 + + '@esbuild/aix-ppc64@0.28.2': + optional: true + + '@esbuild/android-arm64@0.28.2': + optional: true + + '@esbuild/android-arm@0.28.2': + optional: true + + '@esbuild/android-x64@0.28.2': + optional: true + + '@esbuild/darwin-arm64@0.28.2': + optional: true + + '@esbuild/darwin-x64@0.28.2': + optional: true + + '@esbuild/freebsd-arm64@0.28.2': + optional: true + + '@esbuild/freebsd-x64@0.28.2': + optional: true + + '@esbuild/linux-arm64@0.28.2': + optional: true + + '@esbuild/linux-arm@0.28.2': + optional: true + + '@esbuild/linux-ia32@0.28.2': + optional: true + + '@esbuild/linux-loong64@0.28.2': + optional: true + + '@esbuild/linux-mips64el@0.28.2': + optional: true + + '@esbuild/linux-ppc64@0.28.2': + optional: true + + '@esbuild/linux-riscv64@0.28.2': + optional: true + + '@esbuild/linux-s390x@0.28.2': + optional: true + + '@esbuild/linux-x64@0.28.2': + optional: true + + '@esbuild/netbsd-arm64@0.28.2': + optional: true + + '@esbuild/netbsd-x64@0.28.2': + optional: true + + '@esbuild/openbsd-arm64@0.28.2': + optional: true + + '@esbuild/openbsd-x64@0.28.2': + optional: true + + '@esbuild/openharmony-arm64@0.28.2': + optional: true + + '@esbuild/sunos-x64@0.28.2': + optional: true + + '@esbuild/win32-arm64@0.28.2': + optional: true + + '@esbuild/win32-ia32@0.28.2': + optional: true + + '@esbuild/win32-x64@0.28.2': + optional: true + + '@standard-schema/spec@1.1.0': {} + + esbuild@0.28.2: + optionalDependencies: + '@esbuild/aix-ppc64': 0.28.2 + '@esbuild/android-arm': 0.28.2 + '@esbuild/android-arm64': 0.28.2 + '@esbuild/android-x64': 0.28.2 + '@esbuild/darwin-arm64': 0.28.2 + '@esbuild/darwin-x64': 0.28.2 + '@esbuild/freebsd-arm64': 0.28.2 + '@esbuild/freebsd-x64': 0.28.2 + '@esbuild/linux-arm': 0.28.2 + '@esbuild/linux-arm64': 0.28.2 + '@esbuild/linux-ia32': 0.28.2 + '@esbuild/linux-loong64': 0.28.2 + '@esbuild/linux-mips64el': 0.28.2 + '@esbuild/linux-ppc64': 0.28.2 + '@esbuild/linux-riscv64': 0.28.2 + '@esbuild/linux-s390x': 0.28.2 + '@esbuild/linux-x64': 0.28.2 + '@esbuild/netbsd-arm64': 0.28.2 + '@esbuild/netbsd-x64': 0.28.2 + '@esbuild/openbsd-arm64': 0.28.2 + '@esbuild/openbsd-x64': 0.28.2 + '@esbuild/openharmony-arm64': 0.28.2 + '@esbuild/sunos-x64': 0.28.2 + '@esbuild/win32-arm64': 0.28.2 + '@esbuild/win32-ia32': 0.28.2 + '@esbuild/win32-x64': 0.28.2 diff --git a/scripts/build-client.mjs b/scripts/build-client.mjs new file mode 100644 index 0000000..693cb6f --- /dev/null +++ b/scripts/build-client.mjs @@ -0,0 +1,57 @@ +// Builds client.js (browser half) from src/client. Mirrors the DS Bot wrapper so dsh can +// load it as a classic script and resolve platform modules from the shell. +// node scripts/build-client.mjs writes client.js +// node scripts/build-client.mjs --check exit 1 if client.js differs from a fresh build +import { readFileSync, writeFileSync } from 'node:fs' +import { dirname, join } from 'node:path' +import { fileURLToPath } from 'node:url' + +const PLUGIN = dirname(dirname(fileURLToPath(import.meta.url))) +const OUTPUT = join(PLUGIN, 'client.js') +const PLATFORM_MODULES = ['react', 'react-dom', '@deepseek-ai/dsh-client-ui-primitives'] + +export async function bundleClient() { + let esbuild + try { esbuild = await import('esbuild') } catch { + throw new Error('缺少 esbuild:请先在包内安装 devDependencies(pnpm/npm i),再构建 client.js。') + } + const result = await esbuild.build({ + absWorkingDir: PLUGIN, + entryPoints: ['src/client/index.js'], + bundle: true, + format: 'cjs', + platform: 'browser', + target: 'es2022', + external: PLATFORM_MODULES, + treeShaking: false, + charset: 'utf8', + write: false, + logLevel: 'silent', + }) + if (result.warnings.length > 0) throw new Error('esbuild warnings:\n' + result.warnings.map(w => w.text).join('\n')) + return [ + '// Generated from src/client by `npm run build` (scripts/build-client.mjs). Do not edit by hand.', + 'window.__ModuleLoader__.load({', + " id: 'dsh-sansheng-liubu',", + ' factory: (require) => {', + 'const module = { exports: {} }', + result.outputFiles[0].text.trimEnd(), + "return Object.defineProperty({ ...module.exports }, Symbol.toStringTag, { value: 'Module' })", + ' },', + '})', + '', + ].join('\n') +} + +if (process.argv[1] === fileURLToPath(import.meta.url)) { + const next = await bundleClient() + if (process.argv.includes('--check')) { + let current = '' + try { current = readFileSync(OUTPUT, 'utf8') } catch {} + if (current !== next) { console.error('client.js 与 src/client 不一致,请运行 npm run build'); process.exit(1) } + console.log('client.js 是最新的') + } else { + writeFileSync(OUTPUT, next) + console.log('已写出 client.js') + } +} diff --git a/src/client/index.js b/src/client/index.js new file mode 100644 index 0000000..b910c93 --- /dev/null +++ b/src/client/index.js @@ -0,0 +1,563 @@ +// 三省六部 Web 插件入口:左侧追加「三省六部」入口,点开右侧工作台。 +// 所有对宿主可选服务的调用都用 ctx.get(...) 特性探测,探测不到就降级,不伪造接口。 + +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 { request } from './transport.js' +import { CSS as WORKBENCH_CSS } from './styles.js' +import { install as installNativePanel } from '../native/index.js' + +export const inject = ['sessions', 'uiWorkspace', 'uiConversation', 'slots', 'theme', 'layout'] + +const PLUGIN_ID = 'dsh-sansheng' +const TAB_KIND = 'sansheng-workbench' +const TAB_TYPE_ID = 'dsh-sansheng:workbench' + +function installStyles(doc, tag, text) { + if (!doc || !doc.head) return null + const style = doc.createElement('style') + // 带上插件 id,避免被 ClientModuleSystem 当作别人的模块样式回收。 + style.dataset.plugin = PLUGIN_ID + style.dataset.sansheng = tag + style.textContent = text + doc.head.appendChild(style) + return style +} + +// ---------- 小图标(createElement,无 JSX) ---------- +function svgWrap(children, props) { + return h('svg', { + viewBox: '0 0 24 24', width: 16, height: 16, fill: 'none', stroke: 'currentColor', + strokeWidth: 1.6, strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': 'true', + ...(props || {}), + }, children) +} +const TreeIcon = (props) => svgWrap([ + h('rect', { key: 'a', x: 9, y: 2, width: 6, height: 5, rx: 1 }), + h('path', { key: 'b', d: 'M12 7v5M5 16v-4h14v4' }), + h('rect', { key: 'c', x: 2, y: 16, width: 6, height: 5, rx: 1 }), + h('rect', { key: 'd', x: 16, y: 16, width: 6, height: 5, rx: 1 }), +], props) +const CloseIcon = (props) => svgWrap([h('path', { key: 'p', d: 'm6 6 12 12M6 18 18 6' })], props) +const FolderIcon = (props) => svgWrap([h('path', { key: 'p', d: 'M3 7V5a2 2 0 0 1 2-2h5l2 3h7a2 2 0 0 1 2 2v11H3Z' })], props) +const GearIcon = (props) => svgWrap([ + h('path', { key: 'a', d: 'M4 6h16M4 12h16M4 18h16' }), + h('circle', { key: 'b', cx: 9, cy: 6, r: 2 }), + h('circle', { key: 'c', cx: 16, cy: 12, r: 2 }), + h('circle', { key: 'd', cx: 8, cy: 18, r: 2 }), +], props) +const ChevronIcon = (props) => h('svg', { + viewBox: '0 0 24 24', width: 14, height: 14, fill: 'none', stroke: 'currentColor', + strokeWidth: 1.6, strokeLinecap: 'round', strokeLinejoin: 'round', + className: 'ssw-chevron', 'aria-hidden': 'true', +}, h('path', { d: 'm6 9 6 6 6-6' })) + +function isFn(value) { return typeof value === 'function' } +function safeCall(obj, name) { + try { + if (!obj || !isFn(obj[name])) return undefined + return obj[name]() + } catch { return undefined } +} +function snapshotOf(obj) { + if (!obj) return undefined + if (isFn(obj.getSnapshot)) { + try { return obj.getSnapshot() } catch { return undefined } + } + return obj +} + +export function apply(ctx) { + if (typeof document !== 'undefined') installStyles(document, 'workbench', WORKBENCH_CSS) + + const get = (name) => { try { return ctx.get(name) } catch { return undefined } } + + // ---------- 当前项目 / 工作区(特性探测,拿不到就提示用户先选项目) ---------- + function workspaceItems() { + const fromWorkspaces = snapshotOf(get('workspaces')?.list)?.items + if (Array.isArray(fromWorkspaces)) return fromWorkspaces + const fromUi = snapshotOf(get('uiWorkspace')?.workspaces)?.items + if (Array.isArray(fromUi)) return fromUi + return [] + } + + function normalizeWorkspace(item) { + if (!item || typeof item !== 'object') return null + const workspaceId = item.workspaceId ?? item.id ?? null + if (typeof workspaceId !== 'string' || !workspaceId) return null + return { + workspaceId, + name: typeof item.name === 'string' ? item.name : (typeof item.title === 'string' ? item.title : undefined), + path: typeof item.path === 'string' ? item.path : undefined, + } + } + + function currentSessionId() { + const snap = snapshotOf(get('sessions')?.list) ?? snapshotOf(get('sessions')) + if (!snap || typeof snap !== 'object') return null + for (const key of ['activeId', 'currentId', 'selectedId']) { + if (typeof snap[key] === 'string' && snap[key]) return snap[key] + } + if (snap.byId && typeof snap.byId === 'object') { + const main = Object.values(snap.byId).find(session => (session?.retainedBy?.mainView ?? 0) > 0) + if (main && typeof main.id === 'string') return main.id + } + return null + } + + function currentWorkspaceId() { + const candidates = [] + for (const holder of [get('workspaces'), get('uiWorkspace')]) { + if (!holder) continue + for (const key of ['currentWorkspaceId', 'currentId', 'activeId']) { + if (isFn(holder[key])) candidates.push(safeCall(holder, key)) + else if (typeof holder[key] === 'string') candidates.push(holder[key]) + } + for (const key of ['current', 'active', 'selected', 'currentWorkspace']) { + const value = holder[key] + const snap = snapshotOf(value) + if (snap && typeof snap === 'object') candidates.push(snap.workspaceId ?? snap.id) + else if (typeof value === 'string') candidates.push(value) + } + } + const sessionId = currentSessionId() + if (sessionId) { + const owner = workspaceItems().find(item => Array.isArray(item.sessionIds) && item.sessionIds.includes(sessionId)) + if (owner) candidates.push(owner.workspaceId ?? owner.id) + } + return candidates.find(id => typeof id === 'string' && id) ?? null + } + + function currentWorkspace() { + const items = workspaceItems().map(normalizeWorkspace).filter(Boolean) + const id = currentWorkspaceId() + if (id) { + const hit = items.find(item => item.workspaceId === id) + return hit || { workspaceId: id, name: undefined, path: undefined } + } + if (items.length === 1) return items[0] + return null + } + + function seatRecordOf(view, id) { + const seats = view && view.project ? view.project.seats : null + if (Array.isArray(seats)) return seats.find(seat => seat && seat.id === id) || null + if (seats && typeof seats === 'object') return seats[id] || null + return null + } + + // ---------- 会话导航(特性探测;拿不到只发意图并 console.warn) ---------- + function navigateToSession(sessionId) { + if (!sessionId) return false + const attempts = [] + const ui = get('uiWorkspace') + if (ui) { + if (isFn(ui.openSession)) attempts.push(() => ui.openSession(sessionId)) + if (isFn(ui.open)) attempts.push(() => ui.open(sessionId)) + } + const sessions = get('sessions') + if (sessions) { + if (isFn(sessions.open)) attempts.push(() => sessions.open(sessionId)) + if (isFn(sessions.openSession)) attempts.push(() => sessions.openSession(sessionId)) + if (isFn(sessions.select)) attempts.push(() => sessions.select(sessionId)) + } + for (const name of ['navigation', 'navigator', 'router']) { + const svc = get(name) + if (!svc) continue + if (isFn(svc.openSession)) attempts.push(() => svc.openSession(sessionId)) + if (isFn(svc.navigate)) attempts.push(() => svc.navigate({ sessionId })) + if (isFn(svc.open)) attempts.push(() => svc.open(sessionId)) + } + for (const run of attempts) { + try { + const result = run() + if (result && isFn(result.then)) result.catch(() => {}) + return true + } catch { /* 换下一个候选 */ } + } + console.warn('[sansheng] 未找到可用的会话导航接口,仅发出 navigate 意图:', sessionId) + try { + if (typeof window !== 'undefined') { + window.dispatchEvent(new CustomEvent('sansheng:navigate', { detail: { sessionId } })) + } + } catch { /* 忽略 */ } + return false + } + + // ---------- 右侧标签页(真实契约:register 类型 + 正文/标题 slot;不可用时回退浮动面板) ---------- + function ensureRightTab() { + const tabs = get('sidebarRightTabs') + return !!(tabs && isFn(tabs.get) && tabs.get(TAB_KIND)) + } + function tryOpenRightTab() { + const right = get('sidebarRight') + if (!right || !isFn(right.openTab)) return false + if (!ensureRightTab()) return false + try { right.openTab(TAB_KIND); return true } catch (error) { + console.warn('[sansheng] 打开右侧标签失败,改用浮动面板:', error && error.message ? error.message : error) + return false + } + } + function SanshengTabBody() { + return h('div', { className: 'ssw-tab-body' }, h(SanshengWorkbench, {})) + } + function SanshengTabTitle() { + return h('span', { className: 'ssw-tab-title' }, '三省六部') + } + // 宿主按 definition.id 选 slot(TabSlot: entryKey=definition.id),因此 slot key 必须等于类型 id。 + function registerRightTabType() { + try { + if (!isFn(ctx.inject)) return + ctx.inject(['sidebarRightTabs'], (injected) => { + const tabs = injected.get('sidebarRightTabs') + if (!tabs || !isFn(tabs.register)) return + let disposeType = null, disposeBody = null, disposeTitle = null + try { + disposeType = tabs.register({ id: TAB_TYPE_ID, kind: TAB_KIND, keepMounted: true, priority: 'extension', title: () => '三省六部' }) + disposeBody = ctx.slots.inject('sidebar.right.pane.tab', () => ctx.slots.register({ + name: 'sidebar.right.pane.tab', key: TAB_TYPE_ID, inject: (sessionId) => ({ sessionId }), + }, SanshengTabBody)) + disposeTitle = ctx.slots.inject('sidebar.right.pane.tab.title', () => ctx.slots.register({ + name: 'sidebar.right.pane.tab.title', key: TAB_TYPE_ID, inject: (sessionId) => ({ sessionId }), + }, SanshengTabTitle)) + } catch (error) { + console.warn('[sansheng] 注册右侧标签失败:', error && error.message ? error.message : error) + try { disposeBody && disposeBody() } catch { /* 忽略 */ } + try { disposeTitle && disposeTitle() } catch { /* 忽略 */ } + try { disposeType && disposeType() } catch { /* 忽略 */ } + return + } + return () => { + try { disposeBody && disposeBody() } catch { /* 忽略 */ } + try { disposeTitle && disposeTitle() } catch { /* 忽略 */ } + try { disposeType && disposeType() } catch { /* 忽略 */ } + } + }) + } catch (error) { + console.warn('[sansheng] 注册右侧标签失败:', error && error.message ? error.message : error) + } + } + + // ---------- 工作台组件 ---------- + function SanshengWorkbench(props) { + const onClose = props && props.onClose ? props.onClose : null + const [phase, setPhase] = useState('loading') + const [error, setError] = useState(null) + const [notice, setNotice] = useState(null) + const [view, setView] = useState(null) + const [models, setModels] = useState(null) + const [selectedSeatId, setSelectedSeatId] = useState(SEAT_IDS[0]) + const [draft, setDraft] = useState({}) + const [busy, setBusy] = useState(false) + const [configOpen, setConfigOpen] = useState(false) + const [reportOpen, setReportOpen] = useState(false) + const alive = useRef(true) + + useEffect(() => () => { alive.current = false }, []) + + const loadProject = useCallback(async () => { + setPhase('loading'); setError(null); setNotice(null) + const workspace = currentWorkspace() + if (!workspace) { setPhase('no-workspace'); return } + try { + const projectView = await request('open', { + workspaceId: workspace.workspaceId, + name: workspace.name, + path: workspace.path, + }) + let modelCatalog = null + try { modelCatalog = await request('models') } catch (modelError) { + console.warn('[sansheng] 模型目录加载失败:', modelError && modelError.message ? modelError.message : modelError) + } + if (!alive.current) return + setView(projectView) + setModels(modelCatalog) + setPhase('ready') + } catch (loadError) { + if (!alive.current) return + setError(loadError && loadError.message ? loadError.message : '加载失败') + setPhase('error') + } + }, []) + + useEffect(() => { void loadProject() }, [loadProject]) + + 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) + } + const seat = seatById[id] + if (wb.ready && seat && seat.status === 'bound') { + const rec = seatRecordOf(view, id) + if (rec && rec.sessionId) { + navigateToSession(rec.sessionId) + setNotice('已切换到' + seat.name + '会话') + return + } + } + if (wb.ready && seat && seat.status !== 'bound') setNotice('该席尚未绑定会话,先启用或重试启用') + } + + function setModelValue(value) { + setDraft(prev => updateDraft(prev, selectedSeatId, { modelValue: value })) + } + function setInstructions(value) { + setDraft(prev => updateDraft(prev, selectedSeatId, { instructions: value })) + } + + async function enableSeats() { + const projectId = view && view.project ? view.project.id : null + if (!projectId) return + setBusy(true); setError(null); setNotice('正在启用十席…') + try { + const next = await request('enable', { projectId }) + if (!alive.current) return + setView(next) + setNotice('十席已启用(建立独立会话,不自动运行模型)') + } catch (enableError) { + if (alive.current) setError(enableError && enableError.message ? enableError.message : '启用失败') + } finally { + if (alive.current) setBusy(false) + } + } + + async function saveConfig() { + const projectId = view && view.project ? view.project.id : null + if (!projectId) return + const seatId = wb.selected.id + const value = wb.selected.modelValue + if (!value) { setNotice('请先为当前角色选择模型'); return } + const option = findModelOption(wb.selected.modelOptions, value) + const model = option + ? (option.reasoningEffort + ? { provider: option.provider, model: option.model, reasoningEffort: option.reasoningEffort } + : { provider: option.provider, model: option.model }) + : null + setBusy(true); setError(null); setNotice('保存中…') + try { + await request('configure', { projectId, seatId, model, instructions: wb.selected.instructions }) + const next = await request('project', { projectId }) + if (!alive.current) return + setView(next) + setDraft(prev => clearDraft(prev, seatId)) + setNotice('已保存') + } catch (saveError) { + if (alive.current) setError(saveError && saveError.message ? saveError.message : '保存失败') + } finally { + if (alive.current) setBusy(false) + } + } + + const seatCard = (seat) => 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' }, + h('span', { className: 'ssw-eyebrow' }, h(FolderIcon), '当前项目'), + h('span', { className: 'ssw-count' }, wb.project.seatCount + ' 个角色 · ' + wb.project.sessionCount + ' 个会话'), + ), + h('div', { className: 'ssw-project-title' }, wb.projectTitle || '未命名项目'), + ) + + const enableBlock = !wb.ready + ? h('div', { className: 'ssw-enable' }, + h('p', { className: 'ssw-enable-note' }, '这个项目还没有启用十席。启用会建立十个独立会话,但不会自动运行模型。'), + h('button', { + type: 'button', className: 'ssw-primary', disabled: busy, onClick: enableSeats, + }, busy ? '正在启用…' : '启用此项目的十席'), + ) + : null + + const currentCard = 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), + ) + + 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 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) + + 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('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 || '加载失败'), + h('button', { type: 'button', className: 'ssw-primary', onClick: loadProject }, '重试'), + ) + else body = h(Fragment, null, projectInfo, enableBlock, tree, report, currentCard, config, statusEl) + + return h('div', { className: 'ssw-root ssw-scope' }, head, body) + } + + // ---------- 左侧入口 ---------- + function SanshengEntry(props) { + const compact = !!(props && props.compact) + const [floating, setFloating] = useState(false) + const onClick = () => { + if (tryOpenRightTab()) { setFloating(false); return } + setFloating(value => !value) + } + let panel = null + if (floating) { + const card = h('div', { className: 'ssw-float', role: 'dialog', 'aria-label': '三省六部工作台' }, + h(SanshengWorkbench, { onClose: () => setFloating(false) })) + const canPortal = typeof document !== 'undefined' && document.body && isFn(createPortal) + panel = canPortal ? createPortal(card, document.body) : card + } + return h(Fragment, null, + h('button', { + type: 'button', className: compact ? 'ssw-entry ssw-entry-compact' : 'ssw-entry', title: '三省六部', + 'aria-expanded': floating ? 'true' : 'false', onClick, + }, + h(TreeIcon), + h('span', { className: 'ssw-entry-label' }, '三省六部'), + ), + panel, + ) + } + + function SanshengSessionAction(props) { + const children = props && props.children + return h(Fragment, null, children, h(SanshengEntry, { compact: true })) + } + + // 顶部入口:包住「新会话」行(HOC 槽位),在原按钮后追加「三省六部」,不替换原按钮/项目树。 + try { + if (ctx.slots && isFn(ctx.slots.inject) && isFn(ctx.slots.register)) { + ctx.slots.inject('sidebar.session.action', () => ctx.slots.register({ + name: 'sidebar.session.action', + id: 'sansheng-entry', + }, SanshengSessionAction)) + } else { + console.warn('[sansheng] 宿主未提供 slots.inject / slots.register,无法注册侧栏入口') + } + } catch (error) { + console.warn('[sansheng] 注册侧栏入口失败:', error && error.message ? error.message : error) + } + + // 右侧工作台标签类型:需在 apply 时就注册(宿主按类型 id 选正文 slot)。 + registerRightTabType() + + // dsh-go 原生面板:浏览器(无 dshGo 服务)或桥未就绪时,install 内部安静退出。 + try { + installNativePanel(ctx) + } catch (error) { + console.warn('[sansheng] 原生面板注册失败:', error && error.message ? error.message : error) + } +} diff --git a/src/client/styles.js b/src/client/styles.js new file mode 100644 index 0000000..45327b5 --- /dev/null +++ b/src/client/styles.js @@ -0,0 +1,93 @@ +// 三省六部工作台样式:白蓝主题,自带深色适配。 +// 所有选择器以 .ssw- 前缀隔离,避免污染宿主样式;变量参考 preview/index.html。 +// 不依赖任何构建工具,作为普通字符串导出,由入口注入