feat(ui): 保留宿主左侧项目树,Bot 切换移到右栏(v0.2.1) #4
|
|
@ -15,8 +15,8 @@
|
|||
|
||||
| 入口 | 说明 |
|
||||
| --- | --- |
|
||||
| 项目树右键菜单 | 工作区菜单「三省六部 / 初始化三省六部」;会话菜单「打开三省六部」,复用现有项目树,不新增第二棵树 |
|
||||
| 右栏「角色」页签 | 当前项目的丞相 / 尚书 / 工部三张卡片;点击角色打开真实会话;配置与历史审查默认折叠 |
|
||||
| 项目树 / 入口 | 左栏沿用宿主项目树;底部「三省」打开右栏工作台;右栏提供「Bot 切换」折叠列表,不把 Bot 列表塞进左栏 |
|
||||
| 右栏「角色」页签 | 当前项目的丞相 / 尚书 / 工部三张卡片;点击角色打开真实会话;配置、历史审查与 Bot 切换默认折叠 |
|
||||
| `sansheng_provision` | 创建项目:三 Bot + 项目群(尚书是管理员);默认名重名时自动加项目后缀,保证全局唯一 |
|
||||
| `sansheng_bind` | 把已有群绑成项目(校验三角色齐全、管理员是尚书、Bot/群唯一) |
|
||||
| `sansheng_status` | 项目、群、角色、模型、目标阶段、返工预算、写租约、成果代次、待核实派发 |
|
||||
|
|
@ -49,7 +49,7 @@
|
|||
## 验证
|
||||
|
||||
```sh
|
||||
node --test --test-isolation=none sansheng/test/*.test.js # 121 tests
|
||||
node --test --test-isolation=none sansheng/test/*.test.js # 123 tests
|
||||
node --check sansheng/client.js && node --check sansheng/index.js
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@
|
|||
| 基准提交 | `3f20f89`(工作树在开工时仅多出交接方案文档) |
|
||||
| 远端 | `origin https://git.qyhhh.top/newbie/dsh-sansheng-liubu.git` |
|
||||
| 根工作区 | `workspaces: ["sansheng", "ds-bot"]`,根 `package.json` 不是 DSH 插件 |
|
||||
| 治理包 | `sansheng/` = `dsh-sansheng-sansheng@0.2.0`(本次发布候选) |
|
||||
| 团队底座 | `ds-bot/` = `ds-bot@0.3.2-sansheng.1`(上游 `Fei2411/DS-Bot@84c3cb8` + 本地 M-01–M-05) |
|
||||
| 治理包 | `sansheng/` = `dsh-sansheng-sansheng@0.2.1`(本次发布候选) |
|
||||
| 团队底座 | `ds-bot/` = `ds-bot@0.3.2-sansheng.2`(上游 `Fei2411/DS-Bot@84c3cb8` + 本地 M-01–M-06) |
|
||||
| Node | v24.21.0(DSH 随附 `~/.dsh/dsh-runtimes/dsh-primary-runtime/dependencies/node/bin/node.exe`) |
|
||||
| 桌面宿主 | DeepSeek Harness 0.2.2-rc.3(`resources/runtime/primary-runtime/runtime.json`) |
|
||||
| 基线测试 | `node --test --test-isolation=none sansheng/test/*.test.js` → 56/56 通过(2026-11-13) |
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ node --check sansheng/index.js
|
|||
| ID | 状态 | 证据 |
|
||||
| --- | --- | --- |
|
||||
| U01 输入框原生底部 | 真实宿主冒烟部分通过 | 测试 profile 1440×900 截图输入框在底部;本方案不接管 `main.conversation`;长消息/连续工具流未测 |
|
||||
| U02 从项目树打开 A | 真实宿主冒烟通过(测试 profile) | 通过右栏初始化「演示项目」后,左栏出现项目与三角色、右栏三卡;workspace-groups 项目树右键未在该 profile 复现(DS Bot 页面占据左栏),组件级 contextMenus 测试通过 |
|
||||
| U02 从项目树打开 A | 真实宿主冒烟通过(测试 profile) | 左栏保持 workspace-groups 项目树;右栏三卡与「Bot 切换」独立于左栏;workspace-groups 右键菜单组件级测试通过 |
|
||||
| U03 右栏重复点击聚焦 | 组件级通过 | `openRolesTab` 优先 better-sidebar/openTabIn;现有测试覆盖回退 |
|
||||
| U04 Better Sidebar 缺失/失败 | 真实宿主冒烟通过(回退入口) | 测试 profile 无 better-sidebar:左栏底部「三省」按钮可打开右栏「角色」页签;见 `03-host-smoke.md` |
|
||||
| U05 小窗口/宽屏/主题 | 部分验证 | 1440×900 浅色截图;深色/窄屏未测 |
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@ profile `web-test` 的 bundles:`@deepseek-ai/dsh-base`、`@deepseek-ai/dsh-web
|
|||
| 通过 UI 创建项目 | 成功创建「演示项目」三 Bot + 项目群;左栏出现 `演示项目 · 三省六部` 与 工部/尚书/丞相;右栏三张角色卡显示、可点击、无“会话缺失” | `evidence/host-right-roles.png` |
|
||||
| 成功回滚与错误提示 | 先尝试把工作目录放进 DSH_HOME,宿主拒绝(“holds DeepSeek Harness data”);UI 显示「初始化失败:…已回滚本次新建的 Bot」,未落半绑定 | 本次运行日志/UI 文本 |
|
||||
| 原生聊天布局 | 输入框保持在底部,右栏展开/收起不影响输入框几何(1440×900 截图) | `evidence/host-right-roles.png` |
|
||||
| 左侧栏保持宿主项目树 | 安装 M-06 后,DS Bot 不再 shadow `sidebar.workspaces`;左栏显示「工作区 / DS Bot / New Session」项目树,不再换成 Bot 列表 | `evidence/host-project-tree-bot-switch.png` |
|
||||
| Bot 切换在右栏 | 右栏角色卡下方新增折叠「Bot 切换 · 4」,列出丞相/工部/尚书/Chief 与项目群,点击打开对应真实会话 | `evidence/host-project-tree-bot-switch.png` |
|
||||
|
||||
HTTP 响应原文(初始空状态):
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
# 发布说明(候选版本 v0.2.0 / ds-bot 0.3.2-sansheng.1)
|
||||
# 发布说明(候选版本 v0.2.1 / ds-bot 0.3.2-sansheng.2)
|
||||
|
||||
日期:2026-11-14
|
||||
状态:**候选版本**。可用于隔离测试环境;用户日常 desktop profile 未由实施者修改。
|
||||
|
|
@ -7,8 +7,8 @@
|
|||
|
||||
| 包 | 版本 | 文件 |
|
||||
| --- | --- | --- |
|
||||
| `dsh-sansheng-sansheng` | 0.2.0 | `dist/dsh-sansheng-sansheng-0.2.0.tgz` |
|
||||
| `ds-bot`(上游 0.3.2 + M-01–M-05) | 0.3.2-sansheng.1 | `dist/ds-bot-0.3.2-sansheng.1.tgz` |
|
||||
| `dsh-sansheng-sansheng` | 0.2.1 | `dist/dsh-sansheng-sansheng-0.2.1.tgz` |
|
||||
| `ds-bot`(上游 0.3.2 + M-01–M-05) | 0.3.2-sansheng.2 | `dist/ds-bot-0.3.2-sansheng.2.tgz` |
|
||||
|
||||
云端预发布:`v0.2.0-sansheng`,https://git.qyhhh.top/DeepsSeekHarness/dsh-sansheng-liubu/releases/tag/v0.2.0-sansheng (两个 tarball 已作为 release assets 上传)。
|
||||
|
||||
|
|
@ -31,7 +31,7 @@ node <path-to-pnpm.cjs> pack --pack-destination ..\dist
|
|||
2. 停旧包:从 `dsh.profile.bundles` 移除 `dsh-sansheng-liubu-mode`(不要让旧十席与新方案同时注册入口)。
|
||||
3. 安装两个 tarball:
|
||||
```powershell
|
||||
dsh plugin --profile desktop add <绝对路径>\dsh-sansheng-sansheng-0.2.0.tgz <绝对路径>\ds-bot-0.3.2-sansheng.1.tgz
|
||||
dsh plugin --profile desktop add <绝对路径>\dsh-sansheng-sansheng-0.2.1.tgz <绝对路径>\ds-bot-0.3.2-sansheng.2.tgz
|
||||
```
|
||||
4. 确认 `dsh.profile.bundles` 含 `dsh-sansheng-sansheng` 与 `ds-bot`。
|
||||
5. 彻底重启 DSH(插件宿主半改动只有重启生效)。
|
||||
|
|
|
|||
Binary file not shown.
|
After Width: | Height: | Size: 56 KiB |
|
|
@ -172,6 +172,28 @@ const rt = ctx.get('dsbot-runtime', false) // 未安装打过补丁的 ds-bot
|
|||
键;不改变 own/group 记忆、不改变文件格式。无治理服务时 `teamAllowedFor` 为 true、
|
||||
`readScopes` 原样返回,行为与上游一致。
|
||||
|
||||
## M-06:保留宿主左侧项目树,Bot 切换移到右栏
|
||||
|
||||
`client.js`(构建产物)的 `installShell` 原本无条件 shadow `sidebar.workspaces` 为
|
||||
`TeamSidebar`,导致安装三省六部后左栏被 DS Bot 的 Bot 列表替换。补丁改为:当宿主
|
||||
`sidebarRightTabs` 中已存在 `sansheng-roles`(三省六部右栏页签)时跳过 TeamSidebar
|
||||
的 shadow,保留宿主 workspace-groups 项目树;Bot/群切换由右栏「Bot 切换」折叠列表
|
||||
承担(数据来自 `/sansheng/state` 的只读花名册)。
|
||||
|
||||
```diff
|
||||
- () => shadow("sidebar.workspaces", { priority: BOT_PRIORITY, inject: face }, TeamSidebar),
|
||||
+ () => {
|
||||
+ try {
|
||||
+ if (ctx.sidebarRightTabs?.get?.("sansheng-roles") !== undefined) return;
|
||||
+ } catch (error) { /* no workbench: keep the team sidebar */ }
|
||||
+ return shadow("sidebar.workspaces", { priority: BOT_PRIORITY, inject: face }, TeamSidebar)();
|
||||
+ },
|
||||
```
|
||||
|
||||
原因:用户明确要求左侧沿用现有项目树,Bot 切换不要占左栏。
|
||||
影响面:只影响与 `dsh-sansheng-sansheng` 同时安装时的左栏;未装三省六部时行为与上游一致。
|
||||
恢复:删除该条件,恢复原始 `shadow("sidebar.workspaces", ...)` 行即可。
|
||||
|
||||
## 升级步骤
|
||||
|
||||
1. 取新版本 npm tarball,解压覆盖本目录(保留本文件与 `NOTICE`)。
|
||||
|
|
@ -179,7 +201,8 @@ const rt = ctx.get('dsbot-runtime', false) // 未安装打过补丁的 ds-bot
|
|||
并同步修改 `sansheng/src/runtime.js` 的取用名。
|
||||
3. 逐一重放其余补丁:M-02 检查 `cordis.patch.yml`,M-03 重放 `client.js` 的
|
||||
`settings.trigger` try/catch,M-04/M-05 按本文件 diff 恢复 `delivery.js`、
|
||||
`memory.js`、`tools.js` 的治理检查(并对三个文件跑 `node --check`)。
|
||||
`memory.js`、`tools.js` 的治理检查,M-06 重放 `client.js` 的 TeamSidebar 条件
|
||||
shadow(保留左侧项目树);对三个 JS 文件跑 `node --check`。
|
||||
4. 跑 `sansheng` 的单元测试与安装冒烟(见 `docs/install.md`)。
|
||||
|
||||
## 回退
|
||||
|
|
|
|||
|
|
@ -29741,7 +29741,14 @@ function apply(ctx) {
|
|||
() => installFrameWatch(frame),
|
||||
() => installFrameSync(),
|
||||
() => installTheme(),
|
||||
() => shadow("sidebar.workspaces", { priority: BOT_PRIORITY, inject: face }, TeamSidebar),
|
||||
() => {
|
||||
// sansheng M-06: with the 三省六部 workbench installed, keep the host's
|
||||
// project tree in the left sidebar; bot switching lives in the right panel.
|
||||
try {
|
||||
if (ctx.sidebarRightTabs?.get?.("sansheng-roles") !== undefined) return;
|
||||
} catch (error) { /* no workbench: keep the team sidebar */ }
|
||||
return shadow("sidebar.workspaces", { priority: BOT_PRIORITY, inject: face }, TeamSidebar)();
|
||||
},
|
||||
() => shadow("sidebar.brand.mark", { priority: BOT_PRIORITY }, BrandMark),
|
||||
() => shadow("sidebar.brand.name", { priority: BOT_PRIORITY }, BrandName),
|
||||
() => shadow("sidebar.footer.action", { id: "bot-account", order: -200, inject: face }, FooterAccount),
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "ds-bot",
|
||||
"version": "0.3.2-sansheng.1",
|
||||
"version": "0.3.2-sansheng.2",
|
||||
"description": "DS Bot: a team of long-lived Bots for DeepSeek Harness, with Main Bots, Bot-to-Bot messages and group chats",
|
||||
"keywords": [
|
||||
"dsh-plugin",
|
||||
|
|
|
|||
|
|
@ -77,6 +77,13 @@ window.__ModuleLoader__.load({
|
|||
.ss-history{display:flex;flex-direction:column;gap:5px;padding-top:2px}
|
||||
.ss-history-item{display:flex;align-items:baseline;gap:6px;font-size:11px;line-height:16px;color:var(--dsw-alias-label-secondary,#5b616b);min-width:0}
|
||||
.ss-history-item b{font-weight:600}
|
||||
.ss-bot-list{display:flex;flex-direction:column;gap:2px;padding-top:2px}
|
||||
.ss-bot-rooms{border-top:1px solid var(--dsw-alias-border-l1,rgba(127,127,127,.14));margin-top:6px;padding-top:6px}
|
||||
.ss-bot-row{display:flex;align-items:center;gap:6px;width:100%;min-width:0;border:0;background:none;color:inherit;font:inherit;font-size:12px;line-height:22px;padding:3px 6px;border-radius:6px;cursor:pointer;text-align:left}
|
||||
.ss-bot-row:hover,.ss-bot-row:focus-visible{background:var(--dsw-alias-bg-layer-2,rgba(127,127,127,.08))}
|
||||
.ss-bot-name{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-weight:500}
|
||||
.ss-bot-role,.ss-bot-project{font-size:10.5px;color:var(--dsw-alias-label-tertiary,#8a8f98);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
||||
.ss-bot-project{margin-left:auto;max-width:45%}
|
||||
.ss-history-meta{margin-left:auto;color:var(--dsw-alias-label-tertiary,#8a8f98);white-space:nowrap;font-size:10px}
|
||||
.ss-empty{display:flex;flex-direction:column;gap:8px;align-items:flex-start;padding:18px 4px;color:var(--dsw-alias-label-secondary,#5b616b);font-size:12px}
|
||||
.ss-empty .ss-details{width:100%;box-sizing:border-box}
|
||||
|
|
@ -309,7 +316,6 @@ window.__ModuleLoader__.load({
|
|||
function createStatePoller(options) {
|
||||
const opts = options || {}
|
||||
const ctx = opts.ctx
|
||||
const activeProjectId = opts.activeProjectId || ''
|
||||
const fetchImpl = opts.fetchImpl || (typeof fetch === 'function' ? fetch : null)
|
||||
const intervalMs = Number.isFinite(opts.intervalMs) ? opts.intervalMs : POLL_MS
|
||||
const onChange = typeof opts.onChange === 'function' ? opts.onChange : () => {}
|
||||
|
|
@ -326,14 +332,9 @@ window.__ModuleLoader__.load({
|
|||
const tick = async () => {
|
||||
if (stopped) return
|
||||
const requestId = ++latestRequestId
|
||||
const hostContext = workspaceContextOf(ctx)
|
||||
const picked = activeProjectId && lastData
|
||||
? projectsOf(lastData).find(project => project && project.id === activeProjectId)
|
||||
: null
|
||||
const overrideWorkspaceId = picked && picked.workspaceId ? String(picked.workspaceId) : ''
|
||||
const context = overrideWorkspaceId
|
||||
? { workspaceId: overrideWorkspaceId, sessionId: null, path: '', displayTitle: '' }
|
||||
: hostContext
|
||||
// 项目切换以宿主当前 workspace 为准;不拿上次下拉选择去覆盖它,
|
||||
// 否则从项目树切到 B 后仍会请求 A 的工作区,右栏永远停在旧项目。
|
||||
const context = workspaceContextOf(ctx)
|
||||
const signature = contextSignature(context)
|
||||
let retryImmediately = false
|
||||
try {
|
||||
|
|
@ -342,7 +343,7 @@ window.__ModuleLoader__.load({
|
|||
if (!response || response.ok === false) throw new Error('HTTP ' + (response && response.status ? response.status : '???'))
|
||||
const data = await response.json()
|
||||
if (stopped || isStale(requestId, latestRequestId)) return
|
||||
if (!overrideWorkspaceId && contextSignature(workspaceContextOf(ctx)) !== signature) {
|
||||
if (contextSignature(workspaceContextOf(ctx)) !== signature) {
|
||||
retryImmediately = true
|
||||
return
|
||||
}
|
||||
|
|
@ -876,6 +877,34 @@ window.__ModuleLoader__.load({
|
|||
])
|
||||
}
|
||||
|
||||
function BotSwitcher({ ctx, data }) {
|
||||
const bots = Array.isArray(data && data.bots) ? data.bots : []
|
||||
const rooms = Array.isArray(data && data.rooms) ? data.rooms : []
|
||||
if (bots.length === 0 && rooms.length === 0) return null
|
||||
const open = sessionId => {
|
||||
if (!sessionId) return
|
||||
const result = openHostSession(ctx, sessionId)
|
||||
if (result !== true) notifyUser(ctx, result || '打开 Bot 会话失败。')
|
||||
}
|
||||
const row = (item, kind) => h('button', {
|
||||
key: kind + ':' + item.id,
|
||||
type: 'button',
|
||||
className: 'ss-bot-row',
|
||||
title: item.projectName ? `${item.name} · ${item.projectName}` : item.name,
|
||||
onClick: () => open(item.sessionId),
|
||||
}, [
|
||||
h('span', { key: 'name', className: 'ss-bot-name', children: item.name }),
|
||||
item.role && item.role !== item.name ? h('span', { key: 'role', className: 'ss-bot-role', children: item.role }) : null,
|
||||
item.isMain ? h('span', { key: 'main', className: 'ss-chip', children: 'Main' }) : null,
|
||||
item.projectName ? h('span', { key: 'project', className: 'ss-bot-project', children: item.projectName }) : null,
|
||||
].filter(Boolean))
|
||||
return h('details', { className: 'ss-details' }, [
|
||||
h('summary', { key: 'summary', className: 'ss-summary', children: `Bot 切换 · ${bots.length}` }),
|
||||
bots.length > 0 ? h('div', { key: 'bots', className: 'ss-bot-list' }, bots.map(bot => row(bot, 'bot'))) : null,
|
||||
rooms.length > 0 ? h('div', { key: 'rooms', className: 'ss-bot-list ss-bot-rooms' }, rooms.map(room => row(room, 'room'))) : null,
|
||||
])
|
||||
}
|
||||
|
||||
function EmptyHint({ error }) {
|
||||
return h('div', { className: 'ss-empty' }, [
|
||||
error ? h('div', { key: 'error', className: 'ss-error', children: `读不到项目状态:${error}` }) : null,
|
||||
|
|
@ -890,10 +919,10 @@ window.__ModuleLoader__.load({
|
|||
const projects = projectsOf(data)
|
||||
const current = data && data.current ? data.current : null
|
||||
const context = props.context || workspaceContextOf(ctx)
|
||||
let project = activeId ? projects.find(item => item && item.id === activeId) : null
|
||||
if (!project) project = current
|
||||
let project = current
|
||||
if (!project && !context.workspaceId) project = activeId ? projects.find(item => item && item.id === activeId) : null
|
||||
if (!project && !context.workspaceId) project = projects[0] || null
|
||||
const uninitialized = !project && Boolean(context && context.workspaceId) && (Boolean(data) || (!loading && !error))
|
||||
if (!project && !uninitialized) project = projects[0] || null
|
||||
const phase = project ? phaseOf(project) : uninitialized ? '未初始化' : ''
|
||||
const barName = project
|
||||
? project.name
|
||||
|
|
@ -903,8 +932,8 @@ window.__ModuleLoader__.load({
|
|||
const attention = attentionOf(project)
|
||||
const disconnected = Boolean(error)
|
||||
const bar = h('div', { key: 'bar', className: 'ss-bar' }, [
|
||||
projects.length > 1 && project && typeof onPick === 'function'
|
||||
? h('select', { key: 'select', value: project.id, onChange: onPick, 'aria-label': '选择项目' },
|
||||
project && projects.length > 0 && typeof onPick === 'function'
|
||||
? h('select', { key: 'select', value: project.id, onChange: onPick, 'aria-label': '切换项目' },
|
||||
projects.map(item => h('option', { key: item.id, value: item.id, children: item.name })))
|
||||
: h('strong', { key: 'name', children: barName }),
|
||||
phase ? h('span', { key: 'phase', className: 'ss-phase', 'data-tone': phaseToneOf(phase), children: phase }) : null,
|
||||
|
|
@ -924,6 +953,7 @@ window.__ModuleLoader__.load({
|
|||
const roles = rolesOf(project)
|
||||
body = [
|
||||
...roles.map(card => h(RoleCard, { key: card.role || card.label, ctx, project, card })),
|
||||
h(BotSwitcher, { key: 'bots', ctx, data }),
|
||||
h(HistoryPanel, { key: 'history', project }),
|
||||
h(ConfigPanel, { key: 'config', ctx, project, onRefresh }),
|
||||
]
|
||||
|
|
@ -947,6 +977,12 @@ window.__ModuleLoader__.load({
|
|||
const next = event.target.value
|
||||
setActiveId(next)
|
||||
try { window.localStorage.setItem(ACTIVE_KEY, next) } catch (error) { /* 忽略 */ }
|
||||
// 选择项目 = 切到该项目的宿主 workspace,再打开它的工作台会话;
|
||||
// 不是只换右栏文案,避免左栏项目树和右栏状态脱节。
|
||||
const picked = projectsOf(state.data).find(project => project && project.id === next)
|
||||
if (picked && picked.workspaceId) {
|
||||
void openWorkbench(ctx, picked.workspaceId)
|
||||
}
|
||||
}
|
||||
return h(RolesView, {
|
||||
...state,
|
||||
|
|
@ -1069,6 +1105,7 @@ window.__ModuleLoader__.load({
|
|||
RolesView,
|
||||
RolesColumn,
|
||||
RoleCard,
|
||||
BotSwitcher,
|
||||
ConfigPanel,
|
||||
HistoryPanel,
|
||||
InitPanel,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "dsh-sansheng-sansheng",
|
||||
"version": "0.2.0",
|
||||
"version": "0.2.1",
|
||||
"private": true,
|
||||
"description": "三省六部:在 DS Bot 团队上提供丞相/尚书/工部三角色、目标门禁与审查记录。",
|
||||
"type": "module",
|
||||
|
|
|
|||
|
|
@ -309,6 +309,38 @@ export function buildStatePayload({ store, dsbot, now = Date.now() }) {
|
|||
return { generatedAt: now, projects }
|
||||
}
|
||||
|
||||
/** 当前 DS Bot 花名册(只读),供右栏「Bot 切换」使用;不改变项目绑定。 */
|
||||
export function listBots({ dsbot, store }) {
|
||||
let state = {}
|
||||
try { state = dsbot.snapshot() ?? {} } catch { state = {} }
|
||||
const mainIds = new Set(state.mainBotIds ?? [])
|
||||
const bots = Object.values(state.bots ?? {}).map(bot => {
|
||||
const project = typeof store.projectsByBot === 'function' ? store.projectsByBot(bot.id)[0] : store.projectByBot(bot.id)
|
||||
return {
|
||||
id: bot.id,
|
||||
name: bot.name ?? bot.id,
|
||||
role: bot.role ?? null,
|
||||
model: bot.model ?? null,
|
||||
sessionId: bot.sessionId ?? bot.id,
|
||||
isMain: mainIds.has(bot.id),
|
||||
projectId: project?.id ?? null,
|
||||
projectName: project?.name ?? null,
|
||||
}
|
||||
}).sort((a, b) => String(a.name).localeCompare(String(b.name), 'zh-Hans-CN'))
|
||||
const rooms = Object.values(state.rooms ?? {}).map(room => {
|
||||
const project = typeof store.projectByRoom === 'function' ? store.projectByRoom(room.id) : undefined
|
||||
return {
|
||||
id: room.id,
|
||||
name: room.name ?? room.id,
|
||||
sessionId: room.sessionId ?? room.id,
|
||||
memberCount: (room.members ?? []).length,
|
||||
projectId: project?.id ?? null,
|
||||
projectName: project?.name ?? null,
|
||||
}
|
||||
}).sort((a, b) => String(a.name).localeCompare(String(b.name), 'zh-Hans-CN'))
|
||||
return { bots, rooms }
|
||||
}
|
||||
|
||||
/** 根据 workspaceId / sessionId 找出当前项目(由调用方决定 workspaceId 来源)。 */
|
||||
export function resolveCurrentProject(payload, { workspaceId, sessionId } = {}) {
|
||||
const projects = payload?.projects ?? []
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { buildStatePayload, resolveCurrentProject } from './api.js'
|
||||
import { buildStatePayload, listBots, resolveCurrentProject } from './api.js'
|
||||
import { provisionProject, updateProjectConfig } from './provision.js'
|
||||
|
||||
const BODY_LIMIT = 128 * 1024
|
||||
|
|
@ -110,6 +110,7 @@ export function installRoute({ ctx, store, dsbot }) {
|
|||
const health = typeof store.health === 'function' ? store.health() : { status: 'ok' }
|
||||
send(res, 200, {
|
||||
...payload,
|
||||
...listBots({ dsbot, store }),
|
||||
current: current.project ?? null,
|
||||
currentMatch: current.matchedBy,
|
||||
health: { status: health.status, error: health.error ?? null },
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
import { buildStatePayload, resolveCurrentProject } from '../src/api.js'
|
||||
import { buildStatePayload, listBots, resolveCurrentProject } from '../src/api.js'
|
||||
|
||||
function fakeStore({ project, reviews = [], unknown = 0, artifacts = [] } = {}) {
|
||||
return {
|
||||
|
|
@ -129,6 +129,30 @@ test('DS Bot 没有 sessionId 字段时用 Bot id 作为私聊会话 id', () =>
|
|||
assert.equal(card.roles.every(item => item.clickable), true)
|
||||
})
|
||||
|
||||
test('listBots 返回 Bot/群花名册供右栏切换,不改变项目绑定', () => {
|
||||
const dsbot = {
|
||||
snapshot: () => ({
|
||||
mainBotIds: ['b-lead'],
|
||||
bots: {
|
||||
'b-lead': { id: 'b-lead', name: '丞相', role: '丞相' },
|
||||
'b-shang': { id: 'b-shang', name: '尚书', role: '尚书', model: 'm2' },
|
||||
'b-gong': { id: 'b-gong', name: '工部', role: '工部' },
|
||||
},
|
||||
rooms: { 'room-1': { id: 'room-1', name: '示例群', members: ['b-lead', 'b-shang'], admin: 'b-shang' } },
|
||||
}),
|
||||
}
|
||||
const store = {
|
||||
projectsByBot: id => (['b-lead', 'b-shang', 'b-gong'].includes(id) ? [project] : []),
|
||||
projectByRoom: roomId => (roomId === 'room-1' ? project : undefined),
|
||||
}
|
||||
const result = listBots({ dsbot, store })
|
||||
assert.equal(result.bots.length, 3)
|
||||
assert.equal(result.bots.find(bot => bot.id === 'b-lead').isMain, true)
|
||||
assert.equal(result.bots.find(bot => bot.id === 'b-shang').projectId, 'prj-1')
|
||||
assert.equal(result.rooms[0].projectId, 'prj-1')
|
||||
assert.equal(result.bots.find(bot => bot.id === 'b-shang').sessionId, 'b-shang')
|
||||
})
|
||||
|
||||
test('resolveCurrentProject 按 workspaceId 优先,其次 session', () => {
|
||||
const payload = { projects: [{ id: 'prj-1', workspaceId: 'ws-1', roles: [{ sessionId: 'sess-1' }] }] }
|
||||
assert.equal(resolveCurrentProject(payload, { workspaceId: 'ws-1' }).project.id, 'prj-1')
|
||||
|
|
|
|||
|
|
@ -542,3 +542,23 @@ test('初始化项目提交 POST /sansheng/provision 且 body 含 workspaceId/pa
|
|||
const text = textOf(tree)
|
||||
assert.match(text, /此项目尚未初始化/)
|
||||
})
|
||||
|
||||
test('Bot 切换列表在右栏渲染并可打开对应会话', async () => {
|
||||
const { module } = await loadClient()
|
||||
const opened = []
|
||||
const ctx = fakeCtx({ uiWorkspace: { openSession(sessionId) { opened.push(sessionId) } } })
|
||||
const tree = module.__test.BotSwitcher({
|
||||
ctx,
|
||||
data: {
|
||||
bots: [{ id: 'b1', name: '丞相', role: '丞相', sessionId: 'sess-b1', projectName: '项目A' }],
|
||||
rooms: [{ id: 'r1', name: '项目A · 三省六部', sessionId: 'sess-r1', projectName: '项目A' }],
|
||||
},
|
||||
})
|
||||
const text = textOf(tree)
|
||||
assert.match(text, /Bot 切换/)
|
||||
assert.match(text, /丞相/)
|
||||
const buttons = findAll(tree, node => node.type === 'button')
|
||||
assert.ok(buttons.length >= 2)
|
||||
buttons[0].props.onClick()
|
||||
assert.deepEqual(opened, ['sess-b1'])
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue