@ququ-jiaxk/dsh-groupchat 0.1.3 → 0.1.5

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 +119 -4
  2. package/index.js +86 -0
  3. package/package.json +1 -1
package/client.js CHANGED
@@ -10,7 +10,7 @@
10
10
  * - 新建群对话框:群名/描述/初始任务/项目经理会话(留空=自动创建)/成员会话列表
11
11
  */
12
12
  window.__ModuleLoader__.load({
13
- id: '@local/dsh-groupchat',
13
+ id: '@ququ-jiaxk/dsh-groupchat',
14
14
  factory(require) {
15
15
  const React = require('react')
16
16
  const { useState, useEffect, useCallback, useRef } = React
@@ -350,6 +350,26 @@ window.__ModuleLoader__.load({
350
350
  }
351
351
  })()
352
352
 
353
+ // ---- 群聊面板是否处于激活态 ----
354
+ // DSH 的 main 插槽只挂载当前面板:切到别的面板/会话时 GroupchatPanel 会卸载。
355
+ // 所以用「面板挂载 = 激活」来驱动侧栏入口的高亮,不依赖内部 layout store。
356
+ const panelActiveStore = (() => {
357
+ let value = false
358
+ const listeners = new Set()
359
+ return {
360
+ get: () => value,
361
+ set: (next) => {
362
+ if (next === value) return
363
+ value = next
364
+ for (const l of listeners) l()
365
+ },
366
+ subscribe: (listener) => {
367
+ listeners.add(listener)
368
+ return () => listeners.delete(listener)
369
+ },
370
+ }
371
+ })()
372
+
353
373
  // ---- 面板记忆(跨卸载保留 UI 状态) ----
354
374
  // 用户切到别的界面/会话时 GroupchatPanel 会卸载,React state 全部丢失,
355
375
  // 再回来就"重新加载"(回到列表、草稿没了、滚动回顶部)。
@@ -1054,7 +1074,13 @@ window.__ModuleLoader__.load({
1054
1074
 
1055
1075
  // ---- 主面板 ----
1056
1076
  function GroupchatPanel() {
1057
- // 数据来自全局 stateStore(由 globalPoll 驱动),面板不再自己轮询
1077
+ // 挂载 = 群聊面板被选中(DSH 的 main 插槽只挂载当前面板),用于侧栏入口高亮
1078
+ useEffect(() => {
1079
+ panelActiveStore.set(true)
1080
+ return () => panelActiveStore.set(false)
1081
+ }, [])
1082
+
1083
+ // 数据来自全局 stateStore(由全局轮询驱动),面板不再自己轮询
1058
1084
  const [state, setState] = useState(() => stateStore.get())
1059
1085
  // 视图从模块级记忆恢复:切走再切回仍停留在原来的群/标签页
1060
1086
  const [view, setViewRaw] = useState(() => panelMemo.view || 'list') // 'list' | 'create' | 'roster' | 'createProfile' | groupId
@@ -3312,6 +3338,93 @@ window.__ModuleLoader__.load({
3312
3338
  }
3313
3339
 
3314
3340
  // ---- 侧栏图标(带未读角标) ----
3341
+ /**
3342
+ * 侧栏「群聊」入口按钮:与「新会话」并排(`sidebar.session.action` 槽位)。
3343
+ *
3344
+ * 两个约束(都踩过):
3345
+ * 1. 该槽位会把默认的「新会话」按钮作为 children 传进来,必须原样渲染,否则新会话消失。
3346
+ * 2. 那一行是横向 flex,新会话靠 flex:1 占位;我们的按钮**不能设 width:100%**,
3347
+ * 否则会把新会话挤成 0 宽。用自适应宽度 + flexShrink:0,新会话会自然收窄,两者并排。
3348
+ */
3349
+ function GroupchatEntryButton(props) {
3350
+ const wide = !!(props && props.wide)
3351
+ const children = props ? props.children : null
3352
+ const [unread, setUnread] = useState(0)
3353
+ const [active, setActive] = useState(() => panelActiveStore.get())
3354
+ useEffect(() => {
3355
+ const unsubscribe = unreadStore.subscribe(() => setUnread(unreadStore.get()))
3356
+ setUnread(unreadStore.get())
3357
+ return unsubscribe
3358
+ }, [])
3359
+ useEffect(() => {
3360
+ const unsubscribe = panelActiveStore.subscribe(() => setActive(panelActiveStore.get()))
3361
+ setActive(panelActiveStore.get())
3362
+ return unsubscribe
3363
+ }, [])
3364
+ const open = () => {
3365
+ const layout = layoutRef.current
3366
+ if (layout && typeof layout.selectPanel === 'function') layout.selectPanel(PANEL_ID)
3367
+ }
3368
+ // 选中态:主色底 + 主色文字(和其他面板选中时一致的感觉)
3369
+ // 默认态:和「新会话」完全一致(同一套变量、同圆角、同高度、同字号)
3370
+ const idleBg = 'var(--dsw-alias-fill-secondary, rgba(16,41,66,0.05))'
3371
+ const idleColor = 'var(--dsw-alias-label-primary, #102942)'
3372
+ // 激活态:主色实底 + 白字,一眼能看出当前就在群聊
3373
+ const activeBg = 'var(--dsw-alias-accent, #2E6BE6)'
3374
+ const activeColor = '#fff'
3375
+ return h(React.Fragment, null,
3376
+ children,
3377
+ h('button', {
3378
+ type: 'button',
3379
+ 'aria-label': '群聊',
3380
+ 'aria-current': active ? 'page' : undefined,
3381
+ title: '群聊',
3382
+ onClick: open,
3383
+ style: {
3384
+ display: 'flex', alignItems: 'center', justifyContent: 'center',
3385
+ gap: wide ? 6 : 0,
3386
+ height: 34, boxSizing: 'border-box',
3387
+ padding: wide ? '0 6px' : 0,
3388
+ // 高度/圆角/配色与新会话一致;宽度按内容,避免把新会话压成两行
3389
+ flex: '0 0 auto', minWidth: 0, whiteSpace: 'nowrap',
3390
+ border: 'none', cursor: 'pointer',
3391
+ borderRadius: 'var(--dsw-radius-md, 10px)',
3392
+ background: active ? activeBg : idleBg,
3393
+ color: active ? activeColor : idleColor,
3394
+ fontSize: 13, fontWeight: active ? 600 : 500, fontFamily: 'inherit',
3395
+ transition: 'background .15s ease, color .15s ease',
3396
+ },
3397
+ onMouseEnter: (e) => { if (!active) e.currentTarget.style.background = 'var(--dsw-alias-fill-tertiary, rgba(16,41,66,0.09))' },
3398
+ onMouseLeave: (e) => { e.currentTarget.style.background = active ? activeBg : idleBg },
3399
+ onMouseDown: (e) => { if (active) e.currentTarget.style.filter = 'brightness(0.94)' },
3400
+ onMouseUp: (e) => { e.currentTarget.style.filter = 'none' },
3401
+ },
3402
+ h('span', { style: { position: 'relative', display: 'flex', flexShrink: 0 } },
3403
+ h('svg', { width: 16, height: 16, viewBox: '0 0 18 18', fill: 'none', stroke: 'currentColor', strokeWidth: 1.7, strokeLinecap: 'round', strokeLinejoin: 'round' },
3404
+ h('circle', { cx: 6, cy: 7.5, r: 2.2 }),
3405
+ h('circle', { cx: 12, cy: 7.5, r: 2.2 }),
3406
+ 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' }),
3407
+ ),
3408
+ unread > 0 && !wide ? h('span', {
3409
+ style: {
3410
+ position: 'absolute', top: -3, right: -5, minWidth: 13, height: 13, borderRadius: 999,
3411
+ background: '#C0392B', color: '#fff', fontSize: 8, fontWeight: 700,
3412
+ display: 'flex', alignItems: 'center', justifyContent: 'center', padding: '0 3px',
3413
+ },
3414
+ }, unread > 99 ? '99+' : String(unread)) : null,
3415
+ ),
3416
+ wide ? h('span', { style: { whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' } }, '群聊') : null,
3417
+ unread > 0 && wide ? h('span', {
3418
+ style: {
3419
+ minWidth: 16, height: 16, borderRadius: 999, background: '#C0392B', color: '#fff',
3420
+ fontSize: 9, fontWeight: 700, display: 'flex', alignItems: 'center',
3421
+ justifyContent: 'center', padding: '0 4px', flexShrink: 0,
3422
+ },
3423
+ }, unread > 99 ? '99+' : String(unread)) : null,
3424
+ ),
3425
+ )
3426
+ }
3427
+
3315
3428
  function GroupchatIcon() {
3316
3429
  const [unread, setUnread] = useState(0)
3317
3430
  useEffect(() => {
@@ -3419,8 +3532,10 @@ window.__ModuleLoader__.load({
3419
3532
  return () => { clearInterval(globalPollTimer); globalPollTimer = null }
3420
3533
  }, 'groupchat: global poll')
3421
3534
 
3422
- ctx.slots.inject('sidebar.panellist', () =>
3423
- ctx.slots.register({ name: 'sidebar.panellist', id: PANEL_ID, order: 30, label: () => '群聊', locale: NS }, GroupchatIcon),
3535
+ // 侧栏入口:与「新会话」并排(sidebar.session.action 槽位)。
3536
+ // 该槽位是横向 flex 行,我们注册一个自适应宽度的按钮,新会话会随之收窄,两者并排。
3537
+ ctx.slots.inject('sidebar.session.action', () =>
3538
+ ctx.slots.register({ name: 'sidebar.session.action', id: PANEL_ID, locale: NS }, GroupchatEntryButton),
3424
3539
  )
3425
3540
  ctx.slots.inject('main', function* () {
3426
3541
  yield ctx.slots.register({ name: 'main', key: PANEL_ID }, GroupchatPanel)
package/index.js CHANGED
@@ -482,6 +482,40 @@ function deriveGroupStatus(subtasks) {
482
482
  return 'idle'
483
483
  }
484
484
 
485
+ /** 发布到 npm / 插件中心的正式包名(本地开发时 package.json 里是 @local/dsh-groupchat)。 */
486
+ const PUBLISHED_PACKAGE = '@ququ-jiaxk/dsh-groupchat'
487
+
488
+ /** 读自身 package.json:当前版本 + 实际包名(开发版会是 @local/...)。 */
489
+ function readOwnPackage() {
490
+ try {
491
+ const url = new URL('./package.json', import.meta.url)
492
+ const pkg = JSON.parse(readFileSync(url, 'utf8'))
493
+ return { name: pkg.name || '', version: pkg.version || '0.0.0' }
494
+ } catch (_e) {
495
+ return { name: '', version: '0.0.0' }
496
+ }
497
+ }
498
+
499
+ /** 语义化版本比较:a > b 返回 1,a < b 返回 -1,相等返回 0。 */
500
+ function compareVersions(a, b) {
501
+ const parse = (v) => {
502
+ const [core, pre = ''] = String(v || '0.0.0').split('-', 2)
503
+ const nums = core.split('.').map((n) => Number.parseInt(n, 10) || 0)
504
+ return { nums, pre }
505
+ }
506
+ const left = parse(a)
507
+ const right = parse(b)
508
+ for (let i = 0; i < 3; i += 1) {
509
+ const x = left.nums[i] || 0
510
+ const y = right.nums[i] || 0
511
+ if (x !== y) return x > y ? 1 : -1
512
+ }
513
+ if (left.pre === right.pre) return 0
514
+ if (!left.pre) return 1
515
+ if (!right.pre) return -1
516
+ return left.pre > right.pre ? 1 : -1
517
+ }
518
+
485
519
  /** 群任务状态摘要(供 sAgent 查收件箱时带上)。 */
486
520
  function taskSummary(group) {
487
521
  const t = group.task || {}
@@ -1962,6 +1996,58 @@ export function apply(ctx) {
1962
1996
  }
1963
1997
 
1964
1998
  // POST /groupchat/api/groups/:id/read —— 标记群内给用户的消息为已读(打开群时调用,角标清零)
1999
+ // ---- 版本检查 / 更新(对齐插件中心的更新获取方式)----
2000
+ // GET /groupchat/api/version 当前版本 + 最新版本
2001
+ // POST /groupchat/api/version/update 安装指定版本(需重启 DSH 生效)
2002
+ if (pathname === '/groupchat/api/version' && method === 'GET') {
2003
+ const own = readOwnPackage()
2004
+ const manager = (() => { try { return ctx.get('pluginManager') } catch (_e) { return null } })()
2005
+ const base = { current: own.version, packageName: PUBLISHED_PACKAGE, localName: own.name, checkedAt: Date.now() }
2006
+ if (!manager || typeof manager.listVersions !== 'function') {
2007
+ return sendJson(res, 200, { ...base, status: 'unavailable', reason: '当前 DSH 不支持插件版本查询' })
2008
+ }
2009
+ let list
2010
+ try {
2011
+ list = await manager.listVersions(PUBLISHED_PACKAGE)
2012
+ } catch (e) {
2013
+ return sendJson(res, 200, { ...base, status: 'unavailable', reason: String(e && e.message || e) })
2014
+ }
2015
+ if (!list || list.status !== 'listed') {
2016
+ return sendJson(res, 200, { ...base, status: 'unavailable', reason: (list && (list.reason || list.problem)) || '未找到已发布版本' })
2017
+ }
2018
+ const versions = Array.isArray(list.versions) ? list.versions : []
2019
+ // 只认正式版:跳过预发布/已废弃/与本机不兼容的
2020
+ const candidates = versions.filter((v) => v && !v.prerelease && !v.deprecated && !v.incompatible)
2021
+ let latest = null
2022
+ for (const v of candidates) {
2023
+ if (!latest || compareVersions(v.version, latest.version) > 0) latest = v
2024
+ }
2025
+ const latestVersion = latest ? latest.version : null
2026
+ const hasUpdate = !!latestVersion && compareVersions(latestVersion, own.version) > 0
2027
+ return sendJson(res, 200, {
2028
+ ...base,
2029
+ status: hasUpdate ? 'available' : 'current',
2030
+ latest: latestVersion,
2031
+ registry: list.registry || null,
2032
+ })
2033
+ }
2034
+
2035
+ if (pathname === '/groupchat/api/version/update' && method === 'POST') {
2036
+ const body = await readBody(req)
2037
+ const manager = (() => { try { return ctx.get('pluginManager') } catch (_e) { return null } })()
2038
+ if (!manager || typeof manager.updateBundle !== 'function') {
2039
+ return sendJson(res, 200, { ok: false, error: '当前 DSH 不支持插件更新' })
2040
+ }
2041
+ const target = body && body.version ? String(body.version) : ''
2042
+ if (!target) return sendJson(res, 400, { ok: false, error: '缺少目标版本' })
2043
+ try {
2044
+ await manager.updateBundle(PUBLISHED_PACKAGE, target)
2045
+ return sendJson(res, 200, { ok: true, version: target, restartRequired: true })
2046
+ } catch (e) {
2047
+ return sendJson(res, 200, { ok: false, error: String(e && e.message || e) })
2048
+ }
2049
+ }
2050
+
1965
2051
  const readMatch = pathname.match(/^\/groupchat\/api\/groups\/([^/]+)\/read$/)
1966
2052
  if (readMatch && method === 'POST') {
1967
2053
  const group = state.groups.find(g => g.id === readMatch[1])
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ququ-jiaxk/dsh-groupchat",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "type": "module",
5
5
  "description": "DSH 群聊插件:把已有会话作为固定角色的智能体拉进项目群,由项目经理 agent(sAgent)聚合、推进、排人、汇报。",
6
6
  "exports": {