@ququ-jiaxk/dsh-groupchat 0.1.7 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/client.js +619 -248
  2. package/docs/DESIGN.md +1 -1
  3. package/package.json +1 -1
package/client.js CHANGED
@@ -1,11 +1,14 @@
1
1
  /**
2
2
  * dsh-groupchat · Client half (MVP)
3
3
  *
4
- * 入口:左侧栏「群聊」图标(全局,任何会话都可见)。点击后主界面显示群聊面板。
4
+ * 入口:左侧栏顶部「会话 / 群聊」两个 tab(全局,任何会话都可见);
5
+ * 会话模式下插件列表(插件/WorkBuddy…)上方还有一条「+ 新会话」。
6
+ * 群聊模式下左栏的「工作区 / 会话」列表让位给群聊列表(注入原生侧栏渲染),
7
+ * 切回会话时原生工作区列表自动恢复,并点回进群聊前的那个会话。
5
8
  * 数据通过 fetch('/groupchat/api/...') 从 Host 拉取(对齐 ops-board 的已验证通道)。
6
9
  *
7
- * 面板三层:
8
- * - 群列表:群名 + 成员 + 任务状态徽章,顶部「+ 新建群聊」
10
+ * 主面板三层:
11
+ * - 欢迎页:没选中群时的入口(新建群聊 / 花名册)
9
12
  * - 群详情:消息流 + 发消息 + 让项目经理汇报 + 解散群
10
13
  * - 新建群对话框:群名/描述/初始任务/项目经理会话(留空=自动创建)/成员会话列表
11
14
  */
@@ -15,6 +18,13 @@ window.__ModuleLoader__.load({
15
18
  const React = require('react')
16
19
  const { useState, useEffect, useCallback, useRef } = React
17
20
  const h = React.createElement
21
+ // 左栏群聊列表要挂进 DSH 原生侧栏的 DOM,需要一个独立的 React 根。
22
+ // react-dom/client 由宿主平台模块表提供;取不到就放弃注入(主面板不受影响)。
23
+ const ReactDOMClient = (() => {
24
+ try { return require('react-dom/client') } catch (_e) {
25
+ try { return require('react-dom') } catch (_e2) { return null }
26
+ }
27
+ })()
18
28
 
19
29
  const PANEL_ID = 'groupchat'
20
30
  const API = '/groupchat/api'
@@ -281,6 +291,8 @@ window.__ModuleLoader__.load({
281
291
 
282
292
  // ---- 当前会话 id(建群时记录创建者) ----
283
293
  const sessionsRef = { current: null }
294
+ // 进群聊前正在看的会话:群聊模式下工作区列表被替换,返回会话时用它点回原会话
295
+ const lastMainSessionRef = { current: null }
284
296
  // ---- layout 服务(全局 toast 跳转到群聊面板用) ----
285
297
  const layoutRef = { current: null }
286
298
  function getCurrentSessionId() {
@@ -438,6 +450,25 @@ window.__ModuleLoader__.load({
438
450
  statusMenuFor: null,
439
451
  }
440
452
 
453
+ // ---- 当前群聊面板视图(左栏列表用来高亮「正在看的群 / 花名册」) ----
454
+ // 面板内部 state 卸载即丢失,这里单独存一份给侧栏订阅。
455
+ const panelViewStore = (() => {
456
+ let value = panelMemo.view || 'list'
457
+ const listeners = new Set()
458
+ return {
459
+ get: () => value,
460
+ set: (next) => {
461
+ if (next === value) return
462
+ value = next
463
+ for (const l of listeners) l()
464
+ },
465
+ subscribe: (listener) => {
466
+ listeners.add(listener)
467
+ return () => listeners.delete(listener)
468
+ },
469
+ }
470
+ })()
471
+
441
472
  // ---- 当前正在查看的群(用于抑制该群的 toast 通知) ----
442
473
  // 用户在群里看消息时,新消息已经在眼前了,再弹「XX 说…」纯属噪音。
443
474
  const viewingGroupStore = (() => {
@@ -457,20 +488,21 @@ window.__ModuleLoader__.load({
457
488
  }
458
489
  })()
459
490
 
460
- // ---- 面板导航 store(全局 toast「查看群聊 →」跳转用) ----
491
+ // ---- 面板导航 store(全局 toast / 左栏列表 跳转用) ----
492
+ // target 可以是群 id,也可以是 'roster' / 'create' / 'list' 这类视图名。
461
493
  const panelNavStore = (() => {
462
- let openGroupHandler = null
463
- let pendingGroup = null
494
+ let openViewHandler = null
495
+ let pendingView = null
464
496
  return {
465
- // 由 GroupchatPanel 注册:负责把 view 切到某个群
466
- registerOpener: (fn) => { openGroupHandler = fn },
467
- // 跳转到某个群:先切到群聊主面板,再让面板打开对应群
468
- request: (groupId) => {
469
- pendingGroup = groupId
470
- // 面板还没挂载时,选中群聊主面板会让它挂载,挂载后消费 pendingGroup
471
- if (typeof openGroupHandler === 'function') {
472
- openGroupHandler(groupId)
473
- pendingGroup = null
497
+ // 由 GroupchatPanel 注册:负责把 view 切到目标视图
498
+ registerOpener: (fn) => { openViewHandler = fn },
499
+ // 跳转到某个视图:先切到群聊主面板,再让面板打开对应视图
500
+ requestView: (target) => {
501
+ pendingView = target
502
+ // 面板还没挂载时,选中群聊主面板会让它挂载,挂载后消费 pendingView
503
+ if (typeof openViewHandler === 'function') {
504
+ openViewHandler(target)
505
+ pendingView = null
474
506
  return
475
507
  }
476
508
  try {
@@ -479,11 +511,15 @@ window.__ModuleLoader__.load({
479
511
  }
480
512
  } catch (_e) { /* 主面板未注册时忽略 */ }
481
513
  },
482
- // GroupchatPanel 挂载时调用:消费挂起的目标群
514
+ // 兼容旧调用:跳转到某个群
515
+ request: (groupId) => {
516
+ panelNavStore.requestView(groupId)
517
+ },
518
+ // GroupchatPanel 挂载时调用:消费挂起的视图
483
519
  consume: () => {
484
- const g = pendingGroup
485
- pendingGroup = null
486
- return g
520
+ const target = pendingView
521
+ pendingView = null
522
+ return target
487
523
  },
488
524
  }
489
525
  })()
@@ -882,7 +918,7 @@ window.__ModuleLoader__.load({
882
918
  color: T.text, font: "14px/1.6 -apple-system, PingFang SC, 'Segoe UI', sans-serif",
883
919
  background: T.bg, ...style,
884
920
  },
885
- }, children)
921
+ }, ...children)
886
922
 
887
923
  const btn = (text, onClick, kind, size) => h('button', {
888
924
  onClick,
@@ -1128,10 +1164,50 @@ window.__ModuleLoader__.load({
1128
1164
  }, avatar(m.name, m.role, size, m.agentState, m.avatar || null)))
1129
1165
  )
1130
1166
 
1167
+ // ---- 群聊欢迎页(没选中群时的主区域) ----
1168
+ // 群列表在左栏常驻,这里只负责「进来先看到什么」,并给出新建群 / 花名册入口。
1169
+ function GroupchatWelcome({ lang, btn, setView, groups, loading }) {
1170
+ const hasGroups = (groups || []).length > 0
1171
+ return h('div', {
1172
+ 'data-gc-welcome': '',
1173
+ style: {
1174
+ flex: 1, minHeight: 0, display: 'flex', alignItems: 'center', justifyContent: 'center',
1175
+ padding: 40, background: T.bg,
1176
+ },
1177
+ },
1178
+ h('div', { style: { display: 'flex', flexDirection: 'column', alignItems: 'center', textAlign: 'center', maxWidth: 460 } },
1179
+ h('div', {
1180
+ style: {
1181
+ width: 64, height: 64, borderRadius: 20, background: T.accentSoft, color: T.accent,
1182
+ display: 'flex', alignItems: 'center', justifyContent: 'center', marginBottom: 16,
1183
+ },
1184
+ },
1185
+ h('svg', { width: 30, height: 30, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', strokeWidth: 1.6, strokeLinecap: 'round', strokeLinejoin: 'round' },
1186
+ h('path', { d: 'M4 6.5A2.5 2.5 0 0 1 6.5 4h7A2.5 2.5 0 0 1 16 6.5v4A2.5 2.5 0 0 1 13.5 13H9l-3.2 2.6A.8.8 0 0 1 4.5 15v-2.2A2.5 2.5 0 0 1 4 11.2z' }),
1187
+ h('path', { d: 'M17 9h.5A2.5 2.5 0 0 1 20 11.5v3.3a2.5 2.5 0 0 1-.5 1.5V18l-3-2h-3' }),
1188
+ ),
1189
+ ),
1190
+ h('div', { style: { fontSize: 18, fontWeight: 600, letterSpacing: '-0.2px', marginBottom: 8 } }, lang.panel),
1191
+ h('div', { style: { fontSize: 13, color: T.textMuted, lineHeight: 1.7, marginBottom: 18 } },
1192
+ loading
1193
+ ? lang.loading
1194
+ : hasGroups
1195
+ ? '从左侧选择一个群聊,查看消息和任务看板。'
1196
+ : '还没有群聊。新建一个群,把智能体拉进来一起干活。'),
1197
+ h('div', { style: { display: 'flex', gap: 10, alignItems: 'center' } },
1198
+ btn(lang.newGroup, () => setView('create')),
1199
+ btn(lang.roster, () => setView('roster'), 'ghost'),
1200
+ ),
1201
+ ),
1202
+ )
1203
+ }
1204
+
1131
1205
  // ---- 主面板 ----
1132
1206
  function GroupchatPanel() {
1133
1207
  // 挂载 = 群聊面板被选中(DSH 的 main 插槽只挂载当前面板),用于侧栏入口高亮
1134
1208
  useEffect(() => {
1209
+ // 切面板本身不会释放 mainView 引用,所以这里拿到的仍是刚离开的那个会话
1210
+ lastMainSessionRef.current = getCurrentSessionId()
1135
1211
  panelActiveStore.set(true)
1136
1212
  return () => panelActiveStore.set(false)
1137
1213
  }, [])
@@ -1142,6 +1218,7 @@ window.__ModuleLoader__.load({
1142
1218
  const [view, setViewRaw] = useState(() => panelMemo.view || 'list') // 'list' | 'create' | 'roster' | 'createProfile' | groupId
1143
1219
  const setView = useCallback((next) => {
1144
1220
  panelMemo.view = next
1221
+ panelViewStore.set(next)
1145
1222
  setViewRaw(next)
1146
1223
  }, [])
1147
1224
  const [error, setError] = useState(null)
@@ -1165,9 +1242,10 @@ window.__ModuleLoader__.load({
1165
1242
  }
1166
1243
  }, [])
1167
1244
 
1168
- // 注册「打开某个群」的处理器(全局 toast 跳转用),并消费挂起的目标群
1245
+ // 注册视图切换入口(全局 toast / 左栏群聊列表都用它),并消费挂起的视图
1169
1246
  useEffect(() => {
1170
- panelNavStore.registerOpener((groupId) => setView(groupId))
1247
+ panelNavStore.registerOpener((target) => setView(target))
1248
+ panelViewStore.set(panelMemo.view || 'list')
1171
1249
  const pending = panelNavStore.consume()
1172
1250
  if (pending) setView(pending)
1173
1251
  return () => panelNavStore.registerOpener(null)
@@ -1198,153 +1276,12 @@ window.__ModuleLoader__.load({
1198
1276
  if (g) return h(GroupDetail, { lang, input, btn, act, api, wrap, drawer, state, group: g, setView, onChanged: () => reload() })
1199
1277
  }
1200
1278
 
1201
- // ---- 群列表 ----
1279
+ // ---- 欢迎页 ----
1280
+ // 群列表已经移到左侧栏(SidebarGroupList),主区域只显示「选中的群」详情;
1281
+ // 没选群时给一个入口页,避免同一份列表在左右两边重复出现。
1202
1282
  const groups = (state && state.groups) || []
1203
1283
  return wrap({ overflow: 'hidden' },
1204
- // 头部:tab + 新建按钮
1205
- h('div', {
1206
- style: {
1207
- padding: '16px 20px', borderBottom: `1px solid ${T.border}`, background: T.card,
1208
- display: 'flex', alignItems: 'center', justifyContent: 'space-between', flexShrink: 0,
1209
- },
1210
- },
1211
- h('div', { style: { display: 'flex', gap: 20, alignItems: 'center' } },
1212
- tabLink(lang.panel, view === 'list', () => setView('list')),
1213
- tabLink(lang.roster, view === 'roster', () => setView('roster')),
1214
- ),
1215
- h('div', { style: { display: 'flex', alignItems: 'center', gap: 10 } },
1216
- h(VersionBadge, null),
1217
- btn(lang.newGroup, () => setView('create')),
1218
- ),
1219
- ),
1220
- // 群卡片列表
1221
- h('div', { className: 'gc-fade', style: { flex: 1, overflow: 'auto', padding: '16px 20px' } },
1222
- groups.length === 0
1223
- ? h('div', { style: { color: T.textMuted, padding: '40px 0', textAlign: 'center' } }, lang.empty)
1224
- : groups.map((g, gi) => {
1225
- // sAgent 的状态挂在 sAgentState,成员的挂在各自 agentState 上
1226
- const members = [
1227
- { name: g.sAgentName, role: 'manager', agentState: g.sAgentState },
1228
- ...(g.members || []),
1229
- ]
1230
- const status = g.task ? g.task.status : 'idle'
1231
- const unread = g.unreadToUser || 0
1232
- // 有 agent 正在干活(思考/写回复/跑工具/等响应)就亮出状态
1233
- const busyMembers = members.filter(m => {
1234
- const st = m.agentState && (m.agentState.state || m.agentState)
1235
- return st && st !== 'idle' && st !== 'offline'
1236
- })
1237
- return h('div', {
1238
- key: keyOf(g.id),
1239
- onClick: () => setView(g.id),
1240
- className: 'gc-card gc-in',
1241
- style: {
1242
- background: T.card, borderRadius: T.radius, boxShadow: T.shadow,
1243
- padding: '16px 18px', marginBottom: 12, cursor: 'pointer',
1244
- border: '1px solid transparent',
1245
- position: 'relative',
1246
- // 错峰入场:每张卡延后 45ms
1247
- animationDelay: (Math.min(gi, 8) * 45) + 'ms',
1248
- },
1249
- onMouseEnter: (e) => { e.currentTarget.style.boxShadow = T.shadowHover },
1250
- onMouseLeave: (e) => { e.currentTarget.style.boxShadow = T.shadow },
1251
- },
1252
- h('div', { style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: 8 } },
1253
- h('div', { style: { fontSize: 15, fontWeight: 600, letterSpacing: '-0.2px' } }, g.name),
1254
- h('div', { style: { display: 'flex', alignItems: 'center', gap: 8 } },
1255
- unread > 0 ? h('span', {
1256
- // key 跟着数字走:未读数一变就重挂载,触发 pop 动画
1257
- key: 'unread-' + unread,
1258
- className: 'gc-pop',
1259
- style: {
1260
- minWidth: 20, height: 20, borderRadius: '50%', background: T.danger, color: '#fff',
1261
- fontSize: 11, fontWeight: 700, display: 'flex', alignItems: 'center', justifyContent: 'center',
1262
- padding: '0 5px',
1263
- },
1264
- }, unread > 99 ? '99+' : unread) : null,
1265
- badge(({
1266
- idle: lang.taskIdle, doing: lang.taskDoing, blocked: lang.taskBlocked, done: lang.taskDone,
1267
- })[status] || status, status),
1268
- ),
1269
- ),
1270
- g.description ? h('div', { style: { fontSize: 12.5, color: T.textMuted, marginBottom: 8 } }, g.description) : null,
1271
- // 最近一条消息预览(随 2 秒轮询实时更新)
1272
- (() => {
1273
- const all = (state && state.messages) || []
1274
- let last = null
1275
- for (const mm of all) {
1276
- if (mm.groupId !== g.id) continue
1277
- if (!last || mm.ts > last.ts) last = mm
1278
- }
1279
- if (!last) return null
1280
- const body = String(last.content || '').replace(/\s+/g, ' ').trim()
1281
- const isMine = last.authorRole === 'user'
1282
- return h('div', {
1283
- // key 跟消息 id 走:来了新消息就重挂载,闪一次背景提示更新
1284
- key: 'preview-' + last.id,
1285
- className: 'gc-flash',
1286
- style: {
1287
- fontSize: 12, marginBottom: 8, display: 'flex', gap: 4,
1288
- overflow: 'hidden', whiteSpace: 'nowrap', textOverflow: 'ellipsis',
1289
- color: T.textMuted, alignItems: 'baseline',
1290
- borderRadius: 4, padding: '1px 3px', marginLeft: -3,
1291
- },
1292
- title: `${last.authorName}:${body}`,
1293
- },
1294
- h('span', { style: { color: isMine ? T.accent : T.text, fontWeight: 500, flexShrink: 0 } },
1295
- `${last.authorName}:`),
1296
- h('span', { style: { overflow: 'hidden', textOverflow: 'ellipsis' } }, body.slice(0, 80)),
1297
- )
1298
- })(),
1299
- h('div', { style: { display: 'flex', alignItems: 'center', gap: 6, flexWrap: 'wrap' } },
1300
- avatarStack(members, 22),
1301
- h('span', { style: { fontSize: 12, color: T.textMuted } }, members.map(m => m.name).join('、')),
1302
- // 正在干活的成员状态(思考中 / 写回复 / 执行工具 / 等待响应)
1303
- busyMembers.length > 0
1304
- ? h('span', { style: { display: 'inline-flex', alignItems: 'center', gap: 6, marginLeft: 'auto' } },
1305
- busyMembers.slice(0, 2).map((m, i) =>
1306
- h('span', { key: i, style: { display: 'inline-flex', alignItems: 'center', gap: 4 } },
1307
- h('span', { style: { fontSize: 11, color: T.textMuted } }, m.name),
1308
- statePill(m.agentState),
1309
- ),
1310
- ),
1311
- )
1312
- : null,
1313
- ),
1314
- // 当前进行中任务的轮播条(随任务状态实时更新,数据来自 2s 全局轮询)
1315
- (() => {
1316
- const subs = (g.task && g.task.subtasks) || []
1317
- const doing = subs.find(x => x.status === 'doing')
1318
- const blocked = subs.find(x => x.status === 'blocked')
1319
- const current = blocked || doing
1320
- if (!current) return null
1321
- const isBlocked = current.status === 'blocked'
1322
- const label = (isBlocked ? lang.taskBlocked : lang.taskDoing) + ' · ' + current.title
1323
- return h('div', {
1324
- style: {
1325
- marginTop: 8, paddingTop: 8, borderTop: `1px dashed ${T.border}`,
1326
- display: 'flex', alignItems: 'center', gap: 6, overflow: 'hidden',
1327
- },
1328
- title: label,
1329
- },
1330
- h('span', {
1331
- style: {
1332
- width: 7, height: 7, borderRadius: '50%', flexShrink: 0,
1333
- background: isBlocked ? T.warn : T.primary,
1334
- animation: 'groupchatPulse 1.2s ease-in-out infinite',
1335
- },
1336
- }),
1337
- // 超长标题上下轮播(不再左右摆)
1338
- h(VerticalTicker, { text: label, lineHeight: 18, visibleLines: 1, color: isBlocked ? T.warn : T.textMuted }),
1339
- current.ownerName
1340
- ? h('span', { style: { fontSize: 11, color: T.accent, flexShrink: 0 } }, current.ownerName)
1341
- : null,
1342
- )
1343
- })(),
1344
- )
1345
- }),
1346
- ),
1347
- // 新建群抽屉
1284
+ h(GroupchatWelcome, { lang, btn, setView, groups, loading: !state }),
1348
1285
  view === 'create' ? h(CreateGroup, { lang, input, btn, act, api, wrap, drawer, setView, state, onDone: (id) => { reload(); setView(id) } }) : null,
1349
1286
  )
1350
1287
  }
@@ -3471,19 +3408,416 @@ window.__ModuleLoader__.load({
3471
3408
  )
3472
3409
  }
3473
3410
 
3411
+ // ===== 左栏群聊列表 =====
3412
+ // 群聊模式下把原生「工作区 / 会话」列表让出来,在原位置渲染群聊列表;
3413
+ // 切回会话时 GroupchatPanel 卸载 → panelActiveStore=false → 原生列表恢复。
3414
+ // 实现方式:往 [data-sidebar-scrollport] 这个 grid 里追加一个与原生区域同格的容器,
3415
+ // 挂一个独立 React 根(这样面板卸载也不会带走列表)。
3416
+ const GC_SIDEBAR_ATTR = 'data-groupchat-sidebar'
3417
+ const GC_NATIVE_REGION_ATTR = 'data-groupchat-native-region'
3418
+
3419
+ function useStoreValue(store) {
3420
+ const [value, setValue] = useState(() => store.get())
3421
+ useEffect(() => {
3422
+ const unsubscribe = store.subscribe(() => setValue(store.get()))
3423
+ setValue(store.get())
3424
+ return unsubscribe
3425
+ }, [store])
3426
+ return value
3427
+ }
3428
+
3429
+ // 左栏时间显示:刚刚 / N 分钟 / N 小时 / N 天 / M-D
3430
+ function fmtSidebarTime(ts) {
3431
+ if (!ts) return ''
3432
+ const diff = Date.now() - ts
3433
+ if (diff < 60e3) return '刚刚'
3434
+ if (diff < 3600e3) return Math.floor(diff / 60e3) + ' 分钟'
3435
+ if (diff < 86400e3) return Math.floor(diff / 3600e3) + ' 小时'
3436
+ if (diff < 7 * 86400e3) return Math.floor(diff / 86400e3) + ' 天'
3437
+ const d = new Date(ts)
3438
+ return (d.getMonth() + 1) + '-' + d.getDate()
3439
+ }
3440
+
3441
+ // 左栏列表排序:最近有消息的排前面,其次按建群时间
3442
+ function groupIndex(state) {
3443
+ const groups = (state && state.groups) || []
3444
+ const messages = (state && state.messages) || []
3445
+ const lastBy = new Map()
3446
+ for (const m of messages) {
3447
+ const cur = lastBy.get(m.groupId)
3448
+ if (!cur || m.ts > cur.ts) lastBy.set(m.groupId, m)
3449
+ }
3450
+ return groups.map(g => ({ group: g, last: lastBy.get(g.id) || null }))
3451
+ .sort((a, b) => {
3452
+ const ta = a.last ? a.last.ts : (a.group.createdAt || 0)
3453
+ const tb = b.last ? b.last.ts : (b.group.createdAt || 0)
3454
+ if (tb !== ta) return tb - ta
3455
+ return String(a.group.name || '').localeCompare(String(b.group.name || ''), 'zh-Hans-CN')
3456
+ })
3457
+ }
3458
+
3459
+ function sidebarBtn(title, onClick, children) {
3460
+ return h('button', {
3461
+ type: 'button', title, 'aria-label': title, onClick,
3462
+ className: 'gc-side-icon',
3463
+ style: {
3464
+ width: 24, height: 24, flexShrink: 0, border: 'none', borderRadius: 6, padding: 0,
3465
+ background: 'transparent', color: 'var(--dsw-alias-label-secondary, #5B6470)',
3466
+ display: 'flex', alignItems: 'center', justifyContent: 'center', cursor: 'pointer',
3467
+ },
3468
+ onMouseEnter: (e) => { e.currentTarget.style.background = 'var(--dsw-alias-interactive-bg-hover, rgba(16,41,66,0.08))' },
3469
+ onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent' },
3470
+ }, children)
3471
+ }
3472
+
3473
+ // 群头像:用群名首字 + 按名字散列的颜色,避免所有群都是同一只 sAgent 头像
3474
+ const GC_GROUP_COLORS = ['#2E6BE6', '#764ba2', '#1E7D46', '#B7791F', '#C0392B', '#0F766E', '#7C3AED']
3475
+ function groupAvatar(group, size) {
3476
+ const name = String((group && group.name) || '?')
3477
+ let hash = 0
3478
+ for (let i = 0; i < name.length; i++) hash = (hash * 31 + name.charCodeAt(i)) >>> 0
3479
+ const bg = GC_GROUP_COLORS[hash % GC_GROUP_COLORS.length]
3480
+ const st = normalizeAgentState(group && group.sAgentState)
3481
+ const meta = st ? agentStateMeta(st.state) : null
3482
+ return h('div', {
3483
+ title: meta ? group.sAgentName + ':' + meta.label : group.sAgentName,
3484
+ style: {
3485
+ width: size, height: size, borderRadius: Math.round(size * 0.3), flexShrink: 0,
3486
+ background: bg, color: '#fff', fontSize: Math.round(size * 0.44), fontWeight: 600,
3487
+ display: 'flex', alignItems: 'center', justifyContent: 'center', position: 'relative',
3488
+ boxShadow: '0 1px 3px rgba(16,41,66,0.12)', overflow: 'hidden',
3489
+ },
3490
+ },
3491
+ Array.from(name)[0] || '?',
3492
+ meta && meta.busy
3493
+ ? h('span', {
3494
+ style: {
3495
+ position: 'absolute', right: 0, bottom: 0, width: Math.max(9, Math.round(size * 0.3)),
3496
+ height: Math.max(9, Math.round(size * 0.3)), borderRadius: '50%', background: meta.dot,
3497
+ border: '2px solid var(--dsw-specific-sidebar-fill, #F7F8FA)',
3498
+ animation: 'groupchatPulse 1.2s ease-in-out infinite',
3499
+ },
3500
+ })
3501
+ : null,
3502
+ )
3503
+ }
3504
+
3505
+ function SidebarGroupRow({ group, last, active, onClick }) {
3506
+ const unread = group.unreadToUser || 0
3507
+ const members = [
3508
+ { name: group.sAgentName, role: 'manager', agentState: group.sAgentState },
3509
+ ...(group.members || []),
3510
+ ]
3511
+ const busy = members.find(m => {
3512
+ const st = m.agentState && (m.agentState.state || m.agentState)
3513
+ return st && st !== 'idle' && st !== 'offline'
3514
+ })
3515
+ const busyState = busy ? normalizeAgentState(busy.agentState) : null
3516
+ const busyMeta = busyState ? agentStateMeta(busyState.state) : null
3517
+ const preview = last
3518
+ ? (last.authorName + ':' + String(last.content || '').replace(/\s+/g, ' ').trim())
3519
+ : (group.description || '还没有消息')
3520
+ return h('div', {
3521
+ role: 'button', tabIndex: 0,
3522
+ 'aria-current': active ? 'page' : undefined,
3523
+ title: group.name,
3524
+ onClick,
3525
+ onKeyDown: (e) => {
3526
+ if (e.target !== e.currentTarget) return
3527
+ if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); onClick() }
3528
+ },
3529
+ className: 'gc-side-row',
3530
+ style: {
3531
+ display: 'flex', alignItems: 'center', gap: 9,
3532
+ margin: '0 6px 2px', padding: '7px 8px', borderRadius: 9,
3533
+ cursor: 'pointer', position: 'relative',
3534
+ background: active ? 'var(--dsw-alias-interactive-bg-hover, rgba(16,41,66,0.08))' : undefined,
3535
+ },
3536
+ },
3537
+ groupAvatar(group, 30),
3538
+ h('div', { style: { flex: 1, minWidth: 0 } },
3539
+ h('div', { style: { display: 'flex', alignItems: 'center', gap: 6 } },
3540
+ h('div', {
3541
+ style: {
3542
+ flex: 1, minWidth: 0, fontSize: 13, fontWeight: active ? 600 : 500, color: T.text,
3543
+ overflow: 'hidden', whiteSpace: 'nowrap', textOverflow: 'ellipsis', lineHeight: '18px',
3544
+ },
3545
+ }, group.name),
3546
+ unread > 0
3547
+ ? h('span', {
3548
+ style: {
3549
+ minWidth: 16, height: 16, borderRadius: 999, background: T.danger, color: '#fff',
3550
+ fontSize: 9.5, fontWeight: 700, display: 'flex', alignItems: 'center', justifyContent: 'center',
3551
+ padding: '0 4px', flexShrink: 0,
3552
+ },
3553
+ }, unread > 99 ? '99+' : String(unread))
3554
+ : null,
3555
+ ),
3556
+ h('div', { style: { display: 'flex', alignItems: 'center', gap: 5, marginTop: 1 } },
3557
+ h('span', {
3558
+ style: {
3559
+ flex: 1, minWidth: 0, fontSize: 11.5, color: T.textMuted, lineHeight: '16px',
3560
+ overflow: 'hidden', whiteSpace: 'nowrap', textOverflow: 'ellipsis',
3561
+ },
3562
+ }, preview),
3563
+ busyMeta
3564
+ ? h('span', {
3565
+ title: (busy.name || '') + ':' + busyMeta.label,
3566
+ style: {
3567
+ width: 6, height: 6, borderRadius: '50%', background: busyMeta.dot, flexShrink: 0,
3568
+ animation: busyMeta.pulse ? 'groupchatPulse 1.2s ease-in-out infinite' : 'none',
3569
+ },
3570
+ })
3571
+ : null,
3572
+ h('span', { style: { fontSize: 10.5, color: 'var(--dsw-alias-label-caption, #8A94A6)', flexShrink: 0 } },
3573
+ fmtSidebarTime(last && last.ts)),
3574
+ ),
3575
+ ),
3576
+ )
3577
+ }
3578
+
3579
+ function SidebarGroupList() {
3580
+ const state = useStoreValue(stateStore)
3581
+ const view = useStoreValue(panelViewStore)
3582
+ const entries = groupIndex(state)
3583
+ const rosterActive = view === 'roster' || view === 'createProfile'
3584
+ const totalUnread = entries.reduce((sum, e) => sum + (e.group.unreadToUser || 0), 0)
3585
+
3586
+ return h('div', {
3587
+ style: {
3588
+ flex: 1, minHeight: 0, display: 'flex', flexDirection: 'column',
3589
+ boxSizing: 'border-box',
3590
+ },
3591
+ },
3592
+ // 头部:标题 + 未读总数 + 新建群
3593
+ h('div', {
3594
+ style: {
3595
+ display: 'flex', alignItems: 'center', gap: 6, padding: '2px 8px 6px 12px',
3596
+ flexShrink: 0,
3597
+ },
3598
+ },
3599
+ h('span', { style: { fontSize: 12, fontWeight: 600, color: T.textMuted, letterSpacing: '0.3px' } }, '群聊'),
3600
+ h('span', { style: { fontSize: 10.5, color: 'var(--dsw-alias-label-caption, #8A94A6)' } },
3601
+ totalUnread > 0 ? totalUnread + ' 条未读' : entries.length + ' 个'),
3602
+ h('div', { style: { flex: 1 } }),
3603
+ sidebarBtn('新建群聊', () => panelNavStore.requestView('create'),
3604
+ h('svg', { width: 15, height: 15, viewBox: '0 0 16 16', fill: 'none', stroke: 'currentColor', strokeWidth: 1.6, strokeLinecap: 'round' },
3605
+ h('path', { d: 'M8 3.2v9.6M3.2 8h9.6' }))),
3606
+ ),
3607
+ // 群列表
3608
+ h('div', {
3609
+ style: {
3610
+ flex: 1, minHeight: 0, overflowY: 'auto', overflowX: 'hidden',
3611
+ overscrollBehavior: 'contain', paddingBottom: 4,
3612
+ },
3613
+ },
3614
+ entries.length === 0
3615
+ ? h('div', { style: { padding: '18px 16px', fontSize: 12, color: T.textMuted, lineHeight: 1.6 } },
3616
+ '还没有群聊。点右上角 + 新建一个群。')
3617
+ : entries.map(entry => h(SidebarGroupRow, {
3618
+ key: entry.group.id,
3619
+ group: entry.group,
3620
+ last: entry.last,
3621
+ active: view === entry.group.id,
3622
+ onClick: () => panelNavStore.requestView(entry.group.id),
3623
+ })),
3624
+ ),
3625
+ // 底部:花名册(与列表分开,始终可见)
3626
+ h('div', {
3627
+ style: {
3628
+ flexShrink: 0, borderTop: `1px solid ${T.border}`, padding: '4px 6px 6px',
3629
+ },
3630
+ },
3631
+ h('div', {
3632
+ role: 'button', tabIndex: 0,
3633
+ 'aria-current': rosterActive ? 'page' : undefined,
3634
+ title: '花名册',
3635
+ onClick: () => panelNavStore.requestView('roster'),
3636
+ onKeyDown: (e) => {
3637
+ if (e.target !== e.currentTarget) return
3638
+ if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); panelNavStore.requestView('roster') }
3639
+ },
3640
+ className: 'gc-side-row',
3641
+ style: {
3642
+ display: 'flex', alignItems: 'center', gap: 8, padding: '6px 8px', borderRadius: 9,
3643
+ cursor: 'pointer', fontSize: 12.5,
3644
+ color: rosterActive ? T.accent : T.textMuted,
3645
+ fontWeight: rosterActive ? 600 : 500,
3646
+ background: rosterActive ? T.accentSoft : undefined,
3647
+ },
3648
+ },
3649
+ h('svg', { width: 15, height: 15, viewBox: '0 0 16 16', fill: 'none', stroke: 'currentColor', strokeWidth: 1.5, strokeLinecap: 'round', strokeLinejoin: 'round' },
3650
+ h('circle', { cx: 6, cy: 5.5, r: 2.2 }),
3651
+ h('path', { d: 'M2.2 13c0-2 1.5-3.3 3.8-3.3S9.8 11 9.8 13' }),
3652
+ h('path', { d: 'M10.6 6.6a1.8 1.8 0 1 0 0-3.6M12 9.9c1.3.4 2 1.4 2 2.8' }),
3653
+ ),
3654
+ h('span', null, '花名册'),
3655
+ h('div', { style: { flex: 1 } }),
3656
+ // 版本徽标有自己的点击行为,别让它冒泡成「打开花名册」
3657
+ h('div', { style: { display: 'flex' }, onClick: (e) => e.stopPropagation() }, h(VersionBadge, null)),
3658
+ ),
3659
+ ),
3660
+ )
3661
+ }
3662
+
3663
+ // 插件列表顶部的那一项「+ 新会话」。
3664
+ // 挂在 nav.panelList 的第一个子节点,只在会话模式显示(CSS 用 html[data-groupchat-active] 隐藏)。
3665
+ // 点它 = 点原生新会话按钮(保持挂载在入口槽位里,标记 data-groupchat-native-new)。
3666
+ function NewSessionNavRow() {
3667
+ const start = () => {
3668
+ const host = document.querySelector('[data-groupchat-native-new]')
3669
+ const btn = host && host.querySelector('button')
3670
+ if (btn) btn.click()
3671
+ }
3672
+ return h('button', {
3673
+ type: 'button', title: '新建会话', 'aria-label': '新建会话',
3674
+ onClick: start,
3675
+ style: {
3676
+ display: 'flex', alignItems: 'center', gap: 8, width: 'calc(100% - 8px)', boxSizing: 'border-box',
3677
+ minHeight: 32, margin: '2px 4px -8px', padding: '5px 10px', border: 'none', borderRadius: 10,
3678
+ background: 'transparent', color: T.text, fontFamily: 'inherit',
3679
+ fontSize: 12.5, fontWeight: 500, cursor: 'pointer', textAlign: 'left', flex: 'none',
3680
+ },
3681
+ onMouseEnter: (e) => { e.currentTarget.style.background = 'var(--dsw-alias-interactive-bg-hover, rgba(16,41,66,0.08))' },
3682
+ onMouseLeave: (e) => { e.currentTarget.style.background = 'transparent' },
3683
+ },
3684
+ h('svg', {
3685
+ width: 16, height: 16, viewBox: '0 0 18 18', fill: 'none', stroke: 'currentColor',
3686
+ strokeWidth: 1.7, strokeLinecap: 'round', strokeLinejoin: 'round',
3687
+ }, h('path', { d: 'M9 3.6v10.8M3.6 9h10.8' })),
3688
+ h('span', null, '新会话'),
3689
+ )
3690
+ }
3691
+
3692
+ // 侧栏内容宿主:非群聊模式什么都不渲染,原生工作区列表照常显示。
3693
+ function SidebarHost() {
3694
+ const active = useStoreValue(panelActiveStore)
3695
+ useEffect(() => {
3696
+ const html = document.documentElement
3697
+ if (active) html.setAttribute('data-groupchat-active', '')
3698
+ else html.removeAttribute('data-groupchat-active')
3699
+ return () => { html.removeAttribute('data-groupchat-active') }
3700
+ }, [active])
3701
+
3702
+ // 群聊模式下把注入容器撑满导航以下的剩余高度:
3703
+ // 这样群列表自己滚、花名册固定在底部,而不是短列表时footer悬在半空。
3704
+ useEffect(() => {
3705
+ if (!active) return
3706
+ const container = document.querySelector('[' + GC_SIDEBAR_ATTR + ']')
3707
+ const scroll = document.querySelector('[data-sidebar-scrollport]')
3708
+ if (!container || !scroll) return
3709
+ const resize = () => {
3710
+ try {
3711
+ if (scroll.scrollTop !== 0) scroll.scrollTop = 0
3712
+ const bottom = scroll.getBoundingClientRect().bottom
3713
+ const top = container.getBoundingClientRect().top
3714
+ const avail = Math.max(160, Math.round(bottom - top - 4))
3715
+ container.style.height = avail + 'px'
3716
+ } catch (_e) { /* ignore */ }
3717
+ }
3718
+ resize()
3719
+ const timer = setTimeout(resize, 300)
3720
+ let ro = null
3721
+ try {
3722
+ ro = new ResizeObserver(resize)
3723
+ ro.observe(scroll)
3724
+ } catch (_e) { ro = null }
3725
+ window.addEventListener('resize', resize)
3726
+ return () => {
3727
+ clearTimeout(timer)
3728
+ if (ro) { try { ro.disconnect() } catch (_e) { /* ignore */ } }
3729
+ window.removeEventListener('resize', resize)
3730
+ try { container.style.height = '' } catch (_e) { /* ignore */ }
3731
+ }
3732
+ }, [active])
3733
+
3734
+ return h('div', {
3735
+ style: {
3736
+ display: active ? 'flex' : 'none',
3737
+ flexDirection: 'column', minHeight: 0, flex: 1,
3738
+ },
3739
+ }, active ? h(SidebarGroupList) : null)
3740
+ }
3741
+
3742
+ // 把 SidebarHost 挂到原生侧栏(侧栏可能尚未渲染,用轻量轮询等它出现/重挂)
3743
+ let sidebarMount = null
3744
+ function mountGroupchatSidebar() {
3745
+ if (sidebarMount || !ReactDOMClient || typeof ReactDOMClient.createRoot !== 'function') return
3746
+ const state = { container: null, root: null, rowContainer: null, rowRoot: null, timer: null }
3747
+ const ensure = () => {
3748
+ try {
3749
+ const scroll = document.querySelector('[data-sidebar-scrollport]')
3750
+ if (!scroll) return
3751
+ if (!state.container) {
3752
+ const container = document.createElement('div')
3753
+ container.setAttribute(GC_SIDEBAR_ATTR, '')
3754
+ container.style.cssText = 'grid-column:2;grid-row:4;align-self:start;min-height:0;display:flex;flex-direction:column;'
3755
+ state.root = ReactDOMClient.createRoot(container)
3756
+ state.root.render(h(SidebarHost))
3757
+ state.container = container
3758
+ }
3759
+ // 原生工作区区域 = scrollArea 里除我们容器之外的那个 div,打个标记供 CSS 隐藏
3760
+ const region = Array.from(scroll.children).find(
3761
+ el => el.tagName === 'DIV' && !el.hasAttribute(GC_SIDEBAR_ATTR),
3762
+ )
3763
+ if (region && !region.hasAttribute(GC_NATIVE_REGION_ATTR)) region.setAttribute(GC_NATIVE_REGION_ATTR, '')
3764
+ if (state.container.parentNode !== scroll) scroll.appendChild(state.container)
3765
+
3766
+ // 「+ 新会话」= 滚动区上方、插件列表上面的一条,固定可见(不随列表滚走)。
3767
+ // 插到 .scrollRegion 前面(= sidebar root 的直接子节点),不占入口槽位的高度。
3768
+ const scrollRegion = scroll.parentElement
3769
+ const root = scrollRegion && scrollRegion.parentElement
3770
+ if (root && scrollRegion) {
3771
+ if (!state.rowContainer) {
3772
+ const row = document.createElement('div')
3773
+ row.setAttribute('data-groupchat-new-session', '')
3774
+ row.style.cssText = 'flex:none;min-height:0;display:flex;flex-direction:column;'
3775
+ state.rowRoot = ReactDOMClient.createRoot(row)
3776
+ state.rowRoot.render(h(NewSessionNavRow))
3777
+ state.rowContainer = row
3778
+ }
3779
+ if (state.rowContainer.parentNode !== root || state.rowContainer.nextElementSibling !== scrollRegion) {
3780
+ root.insertBefore(state.rowContainer, scrollRegion)
3781
+ }
3782
+ }
3783
+ } catch (e) {
3784
+ console.warn('groupchat sidebar mount failed:', e)
3785
+ }
3786
+ }
3787
+ ensure()
3788
+ state.timer = setInterval(ensure, 1500)
3789
+ sidebarMount = state
3790
+ }
3791
+
3792
+ function unmountGroupchatSidebar() {
3793
+ const state = sidebarMount
3794
+ sidebarMount = null
3795
+ if (!state) return
3796
+ clearInterval(state.timer)
3797
+ try { if (state.rowRoot) state.rowRoot.unmount() } catch (_e) { /* ignore */ }
3798
+ try { if (state.rowContainer) state.rowContainer.remove() } catch (_e) { /* ignore */ }
3799
+ try { if (state.root) state.root.unmount() } catch (_e) { /* ignore */ }
3800
+ try { if (state.container) state.container.remove() } catch (_e) { /* ignore */ }
3801
+ document.querySelectorAll('[' + GC_NATIVE_REGION_ATTR + ']').forEach(el => el.removeAttribute(GC_NATIVE_REGION_ATTR))
3802
+ document.documentElement.removeAttribute('data-groupchat-active')
3803
+ }
3804
+
3474
3805
  /**
3475
- * 侧栏「群聊」入口按钮:与「新会话」并排(`sidebar.session.action` 槽位)。
3806
+ * 侧栏顶部(`sidebar.session.action` 槽位):「会话 / 群聊」两个 tab,
3807
+ * 以及会话模式下的「+ 新会话」入口(就在插件列表上方)。
3476
3808
  *
3477
- * 两个约束(都踩过):
3478
- * 1. 该槽位会把默认的「新会话」按钮作为 children 传进来,必须原样渲染,否则新会话消失。
3479
- * 2. 那一行是横向 flex,新会话靠 flex:1 占位;我们的按钮**不能设 width:100%**,
3480
- * 否则会把新会话挤成 0 宽。用自适应宽度 + flexShrink:0,新会话会自然收窄,两者并排。
3809
+ * 约束(都踩过):
3810
+ * 1. 槽位会把原生「新会话」按钮作为 children 传进来,必须保持挂载,否则新会话动作丢失;
3811
+ * 宽栏下把它视觉隐藏,由「+ 新会话」代触发它的 click。
3812
+ * 2. 槽位外层是 display:contents,根节点直接参与 flex。
3813
+ * 3. 折叠窄栏(wide=false)放不下 tab,保留原生新会话图标 + 群聊图标。
3481
3814
  */
3482
3815
  function GroupchatEntryButton(props) {
3483
3816
  const wide = !!(props && props.wide)
3484
3817
  const children = props ? props.children : null
3485
3818
  const [unread, setUnread] = useState(0)
3486
3819
  const [active, setActive] = useState(() => panelActiveStore.get())
3820
+ const nativeRef = useRef(null)
3487
3821
  useEffect(() => {
3488
3822
  const unsubscribe = unreadStore.subscribe(() => setUnread(unreadStore.get()))
3489
3823
  setUnread(unreadStore.get())
@@ -3494,91 +3828,112 @@ window.__ModuleLoader__.load({
3494
3828
  setActive(panelActiveStore.get())
3495
3829
  return unsubscribe
3496
3830
  }, [])
3497
- const open = () => {
3831
+
3832
+ // 返回会话:切回会话 tab,并把进群聊前正在看的那个会话点回来
3833
+ const returnToConversation = () => {
3498
3834
  const layout = layoutRef.current
3499
- if (layout && typeof layout.selectPanel === 'function') layout.selectPanel(PANEL_ID)
3835
+ if (!layout || typeof layout.selectPanel !== 'function') return
3836
+ const sessionId = lastMainSessionRef.current
3837
+ try { layout.selectPanel(null) } catch (_e) { return }
3838
+ if (!sessionId) return
3839
+ // 工作区列表要等面板挂载后才渲染出来,找到原来那行就点它(= 用户手动切回)
3840
+ const openRow = (attempt) => {
3841
+ if (panelActiveStore.get()) return
3842
+ const row = document.querySelector('[data-row-key="session:' + sessionId + '"]')
3843
+ if (row) { try { row.click() } catch (_e) { /* ignore */ } return }
3844
+ if (attempt < 3) setTimeout(() => openRow(attempt + 1), 250)
3845
+ }
3846
+ setTimeout(() => openRow(0), 120)
3500
3847
  }
3501
- // 选中态:主色底 + 主色文字(和其他面板选中时一致的感觉)
3502
- // 默认态:和「新会话」完全一致(同一套变量、同圆角、同高度、同字号)
3503
- const idleBg = 'var(--dsw-alias-fill-secondary, rgba(16,41,66,0.05))'
3504
- const idleColor = 'var(--dsw-alias-label-primary, #102942)'
3505
- // 激活态:主色实底 + 白字,一眼能看出当前就在群聊
3506
- const activeBg = 'var(--dsw-alias-accent, #2E6BE6)'
3507
- const activeColor = '#fff'
3508
- return h(React.Fragment, null,
3509
- children,
3510
- h('button', {
3511
- type: 'button',
3512
- 'aria-label': '群聊',
3513
- 'aria-current': active ? 'page' : undefined,
3514
- title: '群聊',
3515
- onClick: open,
3516
- style: {
3517
- display: 'flex', alignItems: 'center', justifyContent: 'center',
3518
- gap: wide ? 6 : 0,
3519
- height: 34, boxSizing: 'border-box',
3520
- padding: wide ? '0 6px' : 0,
3521
- // 高度/圆角/配色与新会话一致;宽度按内容,避免把新会话压成两行
3522
- flex: '0 0 auto', minWidth: 0, whiteSpace: 'nowrap',
3523
- border: 'none', cursor: 'pointer',
3524
- borderRadius: 'var(--dsw-radius-md, 10px)',
3525
- background: active ? activeBg : idleBg,
3526
- color: active ? activeColor : idleColor,
3527
- fontSize: 13, fontWeight: active ? 600 : 500, fontFamily: 'inherit',
3528
- transition: 'background .15s ease, color .15s ease',
3848
+ const openGroupchat = () => {
3849
+ if (active) return
3850
+ lastMainSessionRef.current = getCurrentSessionId()
3851
+ const layout = layoutRef.current
3852
+ if (!layout || typeof layout.selectPanel !== 'function') return
3853
+ try { layout.selectPanel(PANEL_ID) } catch (_e) { /* 主面板未注册时忽略 */ }
3854
+ }
3855
+
3856
+ const groupchatIcon = h('svg', {
3857
+ width: 16, height: 16, viewBox: '0 0 18 18', fill: 'none', stroke: 'currentColor',
3858
+ strokeWidth: 1.7, strokeLinecap: 'round', strokeLinejoin: 'round',
3859
+ },
3860
+ h('circle', { cx: 6, cy: 7.5, r: 2.2 }),
3861
+ h('circle', { cx: 12, cy: 7.5, r: 2.2 }),
3862
+ h('path', { d: 'M2.5 14.5c0-1.9 1.3-3.2 3.3-3.2h1.4M15.5 14.5c0-1.9-1.3-3.2-3.3-3.2h-1.4' }),
3863
+ )
3864
+
3865
+ // 折叠窄栏:原生新会话图标 + 群聊图标(tab 放不下)
3866
+ if (!wide) {
3867
+ return h(React.Fragment, null,
3868
+ children,
3869
+ h('button', {
3870
+ type: 'button', title: '群聊', 'aria-label': '群聊',
3871
+ 'aria-current': active ? 'page' : undefined,
3872
+ onClick: openGroupchat,
3873
+ style: {
3874
+ position: 'relative', width: 30, height: 30, flexShrink: 0, padding: 0,
3875
+ border: 'none', borderRadius: 8, cursor: 'pointer',
3876
+ display: 'flex', alignItems: 'center', justifyContent: 'center',
3877
+ background: active ? 'var(--dsw-alias-accent, #2E6BE6)' : 'transparent',
3878
+ color: active ? '#fff' : 'var(--dsw-alias-label-primary, #102942)',
3879
+ },
3529
3880
  },
3530
- onMouseEnter: (e) => { if (!active) e.currentTarget.style.background = 'var(--dsw-alias-fill-tertiary, rgba(16,41,66,0.09))' },
3531
- onMouseLeave: (e) => { e.currentTarget.style.background = active ? activeBg : idleBg },
3532
- onMouseDown: (e) => { if (active) e.currentTarget.style.filter = 'brightness(0.94)' },
3533
- onMouseUp: (e) => { e.currentTarget.style.filter = 'none' },
3534
- },
3535
- h('span', { style: { position: 'relative', display: 'flex', flexShrink: 0 } },
3536
- h('svg', { width: 16, height: 16, viewBox: '0 0 18 18', fill: 'none', stroke: 'currentColor', strokeWidth: 1.7, strokeLinecap: 'round', strokeLinejoin: 'round' },
3537
- h('circle', { cx: 6, cy: 7.5, r: 2.2 }),
3538
- h('circle', { cx: 12, cy: 7.5, r: 2.2 }),
3539
- h('path', { d: 'M2.5 14.5c0-1.9 1.3-3.2 3.3-3.2h1.4M15.5 14.5c0-1.9-1.3-3.2-3.3-3.2h-1.4' }),
3540
- ),
3541
- unread > 0 && !wide ? h('span', {
3881
+ groupchatIcon,
3882
+ unread > 0 ? h('span', {
3542
3883
  style: {
3543
- position: 'absolute', top: -3, right: -5, minWidth: 13, height: 13, borderRadius: 999,
3544
- background: '#C0392B', color: '#fff', fontSize: 8, fontWeight: 700,
3884
+ position: 'absolute', top: -3, right: -4, minWidth: 14, height: 14, borderRadius: 999,
3885
+ background: T.danger, color: '#fff', fontSize: 8, fontWeight: 700,
3545
3886
  display: 'flex', alignItems: 'center', justifyContent: 'center', padding: '0 3px',
3887
+ border: '1.5px solid var(--dsw-specific-sidebar-fill, #fff)', boxSizing: 'content-box',
3546
3888
  },
3547
3889
  }, unread > 99 ? '99+' : String(unread)) : null,
3548
3890
  ),
3549
- wide ? h('span', { style: { whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' } }, '群聊') : null,
3550
- unread > 0 && wide ? h('span', {
3551
- style: {
3552
- minWidth: 16, height: 16, borderRadius: 999, background: '#C0392B', color: '#fff',
3553
- fontSize: 9, fontWeight: 700, display: 'flex', alignItems: 'center',
3554
- justifyContent: 'center', padding: '0 4px', flexShrink: 0,
3555
- },
3556
- }, unread > 99 ? '99+' : String(unread)) : null,
3557
- ),
3558
- )
3559
- }
3891
+ )
3892
+ }
3560
3893
 
3561
- function GroupchatIcon() {
3562
- const [unread, setUnread] = useState(0)
3563
- useEffect(() => {
3564
- const unsubscribe = unreadStore.subscribe(() => setUnread(unreadStore.get()))
3565
- setUnread(unreadStore.get())
3566
- return unsubscribe
3567
- }, [])
3568
- return h('div', { style: { position: 'relative', width: 18, height: 18 } },
3569
- h('svg', { width: 18, height: 18, viewBox: '0 0 18 18', fill: 'none', stroke: 'currentColor', strokeWidth: 1.6, strokeLinecap: 'round', strokeLinejoin: 'round' },
3570
- h('circle', { cx: 6, cy: 8, r: 2.4 }),
3571
- h('circle', { cx: 12, cy: 8, r: 2.4 }),
3572
- h('path', { d: 'M2.5 15c0-2 1.4-3.4 3.5-3.4h1.6M15.5 15c0-2-1.4-3.4-3.5-3.4h-1.6' }),
3573
- ),
3574
- unread > 0 ? h('span', {
3894
+ const tab = (label, selected, onClick) => h('button', {
3895
+ type: 'button', role: 'tab',
3896
+ 'aria-selected': selected ? 'true' : 'false',
3897
+ onClick,
3898
+ style: {
3899
+ flex: 1, minWidth: 0, height: 28, padding: '0 8px', border: 'none', borderRadius: 7,
3900
+ cursor: 'pointer', fontFamily: 'inherit', fontSize: 12.5,
3901
+ fontWeight: selected ? 600 : 500,
3902
+ color: selected ? T.text : T.textMuted,
3903
+ background: selected ? 'var(--dsw-alias-surface, #fff)' : 'transparent',
3904
+ boxShadow: selected ? '0 1px 2px rgba(16,41,66,0.10), 0 0 0 1px rgba(16,41,66,0.04)' : 'none',
3905
+ display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 5,
3906
+ transition: 'background .15s ease, color .15s ease, box-shadow .15s ease',
3907
+ },
3908
+ onMouseEnter: (e) => { if (!selected) e.currentTarget.style.color = T.text },
3909
+ onMouseLeave: (e) => { if (!selected) e.currentTarget.style.color = T.textMuted },
3910
+ }, label)
3911
+
3912
+ return h('div', {
3913
+ style: { display: 'flex', alignItems: 'center', flex: 1, minWidth: 0 },
3914
+ },
3915
+ // 两个 tab:会话 / 群聊(高度固定 32px,不随模式变化,避免把旁边的导入按钮挤动)
3916
+ h('div', {
3917
+ role: 'tablist', 'aria-label': '侧栏视图',
3575
3918
  style: {
3576
- position: 'absolute', top: -2, right: -2, minWidth: 14, height: 14,
3577
- borderRadius: '50%', background: '#C0392B', color: '#fff',
3578
- fontSize: 8, fontWeight: 700, display: 'flex', alignItems: 'center', justifyContent: 'center',
3579
- padding: '0 3px', border: '2px solid #fff',
3919
+ display: 'flex', gap: 2, padding: 2, borderRadius: 9, flex: 1, minWidth: 0,
3920
+ background: 'var(--dsw-alias-fill-secondary, rgba(16,41,66,0.05))',
3580
3921
  },
3581
- }, unread > 99 ? '99+' : unread) : null,
3922
+ },
3923
+ tab('会话', !active, () => { if (active) returnToConversation() }),
3924
+ tab(h(React.Fragment, null,
3925
+ '群聊',
3926
+ unread > 0 ? h('span', {
3927
+ style: {
3928
+ minWidth: 14, height: 14, borderRadius: 999, background: T.danger, color: '#fff',
3929
+ fontSize: 8.5, fontWeight: 700, display: 'inline-flex', alignItems: 'center',
3930
+ justifyContent: 'center', padding: '0 3px', boxSizing: 'border-box',
3931
+ },
3932
+ }, unread > 99 ? '99+' : String(unread)) : null,
3933
+ ), active, openGroupchat),
3934
+ ),
3935
+ // 原生新会话按钮保持挂载(display:none),由插件列表里的「+ 新会话」代触发
3936
+ h('div', { ref: nativeRef, 'data-groupchat-native-new': '', style: { display: 'none' } }, children),
3582
3937
  )
3583
3938
  }
3584
3939
 
@@ -3650,6 +4005,16 @@ window.__ModuleLoader__.load({
3650
4005
  }
3651
4006
  .gc-toast { animation: gcToastIn .28s cubic-bezier(0.22,1,0.36,1) both; }
3652
4007
  .gc-toast-bar { animation: gcToastBar 5s linear forwards; }
4008
+ /* 左栏群聊列表:行 hover / 键盘焦点;群聊模式隐藏原生工作区列表 */
4009
+ html[data-groupchat-active] [data-groupchat-native-region] { display: none !important; }
4010
+ html[data-groupchat-active] [data-groupchat-new-session] { display: none !important; }
4011
+ [data-sidebar-collapsed] [data-groupchat-sidebar],
4012
+ [data-sidebar-collapsed] [data-groupchat-new-session] { display: none !important; }
4013
+ .gc-side-row:hover { background: var(--dsw-alias-interactive-bg-hover, rgba(16,41,66,0.08)); }
4014
+ .gc-side-row:focus-visible {
4015
+ outline: var(--dsw-focus-ring-width, 2px) solid var(--dsw-focus-ring-color, var(--dsw-alias-accent, #2E6BE6));
4016
+ outline-offset: -2px;
4017
+ }
3653
4018
  @media (prefers-reduced-motion: reduce) {
3654
4019
  .gc-card, .gc-in, .gc-fade, .gc-pop, .gc-flash, .gc-toast, .gc-toast-bar { animation: none !important; transition: none !important; }
3655
4020
  }
@@ -3665,8 +4030,14 @@ window.__ModuleLoader__.load({
3665
4030
  return () => { clearInterval(globalPollTimer); globalPollTimer = null }
3666
4031
  }, 'groupchat: global poll')
3667
4032
 
3668
- // 侧栏入口:与「新会话」并排(sidebar.session.action 槽位)。
3669
- // 该槽位是横向 flex 行,我们注册一个自适应宽度的按钮,新会话会随之收窄,两者并排。
4033
+ // 左栏群聊列表:注入原生侧栏,群聊模式下顶替「工作区 / 会话」列表
4034
+ ctx.effect(() => {
4035
+ mountGroupchatSidebar()
4036
+ return () => { unmountGroupchatSidebar() }
4037
+ }, 'groupchat: sidebar list')
4038
+
4039
+ // 侧栏入口:把「新会话 + 群聊」收成一条紧凑图标栏(sidebar.session.action 槽位)。
4040
+ // 行内布局由 GroupchatEntryButton 负责,新会话按钮保持挂载但视觉隐藏。
3670
4041
  ctx.slots.inject('sidebar.session.action', () =>
3671
4042
  ctx.slots.register({ name: 'sidebar.session.action', id: PANEL_ID, locale: NS }, GroupchatEntryButton),
3672
4043
  )
package/docs/DESIGN.md CHANGED
@@ -293,7 +293,7 @@ sAgent = 一个普通会话(专属 persona + 群管理工具集),靠「被
293
293
 
294
294
  | 能力 | 说明 |
295
295
  |---|---|
296
- | 群聊面板 | 左侧栏「群聊」入口 + 主界面群列表(群名/成员/任务徽章) |
296
+ | 群聊面板 | 左栏群聊列表(未读/最近消息/忙闲)+ 主区域群详情;群聊模式下左栏顶替工作区列表,切回会话自动恢复 |
297
297
  | 新建群 | 群名/描述/初始任务;项目经理可自动创建或从花名册选;成员从花名册勾选 |
298
298
  | 群详情 | 消息流 + 发消息 + 让项目经理汇报 + 解散群 |
299
299
  | 角色模板 | 预置 项目经理/产品/研发/测试,各带 persona + 职责 |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ququ-jiaxk/dsh-groupchat",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "type": "module",
5
5
  "description": "DSH 群聊插件:把已有会话作为固定角色的智能体拉进项目群,由项目经理 agent(sAgent)聚合、推进、排人、汇报。",
6
6
  "exports": {