@fabianactor/dsh-lil-whale-group-ui 1.8.15 → 1.10.0

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.
package/icon.png ADDED
Binary file
package/lib/client.js CHANGED
@@ -120,6 +120,41 @@ window.__ModuleLoader__.load({
120
120
  return cachedConfig
121
121
  }
122
122
 
123
+ /**
124
+ * 版本:读两个包当前版本;「检查更新」才去问 npm。
125
+ * 两个包必须一起用,所以两条一起显示、一起说"有没有新的"。
126
+ */
127
+ async function loadVersions() {
128
+ const response = await fetch('/group/api/version', { headers: { accept: 'application/json' } })
129
+ if (!response.ok) throw new Error(`HTTP ${response.status}`)
130
+ return await response.json()
131
+ }
132
+
133
+ async function checkUpdates() {
134
+ const response = await fetch('/group/api/check-update', {
135
+ method: 'POST',
136
+ headers: { 'x-llw-panel': '1' },
137
+ })
138
+ const data = await response.json().catch(() => null)
139
+ if (!response.ok) throw new Error(data?.error ?? `HTTP ${response.status}`)
140
+ return data
141
+ }
142
+
143
+ /** 版本状态 → 一句人话。检查失败要说出原因,不能显示成"已是最新"。 */
144
+ function versionLineOf(state) {
145
+ if (!state) return '还没读到版本'
146
+ if (state.error) return `检查失败:${state.error}`
147
+ const part = (label, side) => {
148
+ if (!side) return `${label} 未知`
149
+ if (side.error) return `${label} ${side.current ?? '未知'}(检查失败:${side.error})`
150
+ if (side.latest == null) return `${label} ${side.current ?? '未知'}`
151
+ if (side.updateAvailable === true) return `${label} ${side.current} → 最新 ${side.latest}`
152
+ if (side.updateAvailable === false) return `${label} ${side.current}(已是最新)`
153
+ return `${label} ${side.current}(最新 ${side.latest},无法比较)`
154
+ }
155
+ return `${part('宿主', state.host)};${part('面板', state.ui)}`
156
+ }
157
+
123
158
  /**
124
159
  * 名字:默认按成员 id 取。
125
160
  * 但同一个人的多段会话会共用一个 id(`lee`),所以如果能拿到这条消息的 `s`,
@@ -1016,41 +1051,77 @@ const Bubble = React.memo(function Bubble({ config, message, onMention, animate
1016
1051
  // "人往下滚到底"(scrollTop 变大)和"内容变短、浏览器把 scrollTop 夹到底"
1017
1052
  // (scrollTop 变小)。后者 distance 也会变成 0,但人其实没想回底部。
1018
1053
  const lastTopRef = useRef(0)
1054
+ // 上一次量到的内容高度:scrollTop 没动、高度变高,说明"人没走、是被顶下去的"。
1055
+ // 2026-11-17 报的第 1 条:贴底时来一条比视口还高的消息,撑开发生在
1056
+ // 跟到底的那几个补丁之后,于是停在半路。这件事靠多设几个 setTimeout 修不好,得看高度。
1057
+ const lastHeightRef = useRef(0)
1019
1058
  const stickToBottom = useCallback(() => {
1020
1059
  const el = scrollRef.current
1021
1060
  if (el) {
1022
1061
  el.scrollTop = el.scrollHeight
1023
1062
  lastTopRef.current = el.scrollTop
1063
+ lastHeightRef.current = el.scrollHeight
1024
1064
  }
1025
1065
  }, [scrollRef])
1026
1066
  const measureBottom = useCallback(() => {
1027
1067
  const el = scrollRef.current
1028
1068
  if (!el) return
1029
1069
  const top = el.scrollTop
1030
- const distance = el.scrollHeight - top - el.clientHeight
1070
+ const height = el.scrollHeight
1071
+ // 人没动、内容变高:这是"贴着底被顶下去",不是"人离开了底"。
1072
+ // 直接补到底,并且仍然算贴底——否则长消息一来就永远停在半路。
1073
+ const grew = height > lastHeightRef.current
1074
+ const movedDown = top >= lastTopRef.current - 1
1075
+ if (atBottomRef.current && grew && movedDown) {
1076
+ lastHeightRef.current = height
1077
+ stickToBottom()
1078
+ return
1079
+ }
1080
+ lastHeightRef.current = height
1081
+ const distance = height - top - el.clientHeight
1031
1082
  const next = distance <= 40
1032
1083
  // 离开底部永远认;回到"底部"只认人往下滚的那一种。
1033
1084
  // 2026-11-16 报的闪烁:翻历史时来新消息,高度被夹了一下、distance=0,
1034
1085
  // 于是被当成"到底了",下一条一来就 stickToBottom 把人弹到底。
1035
- const movedDown = top >= lastTopRef.current - 1
1036
1086
  lastTopRef.current = top
1037
1087
  if (next !== atBottomRef.current && (next === false || movedDown)) {
1038
1088
  atBottomRef.current = next
1039
1089
  setAtBottom(next)
1040
1090
  }
1041
- }, [scrollRef])
1091
+ }, [scrollRef, stickToBottom])
1042
1092
  const jumpToBottom = useCallback(() => {
1043
1093
  atBottomRef.current = true
1044
1094
  setAtBottom(true)
1045
1095
  stickToBottom()
1046
1096
  requestAnimationFrame(stickToBottom)
1047
1097
  }, [stickToBottom])
1098
+ // 贴底时盯着内容高度:Markdown 排版、图片加载、代码块换行都在首帧之后还会长高。
1099
+ // 只认"贴底"这一个前提;人一翻历史就不管——不能把正在看三天前的人拽回今天。
1100
+ useEffect(() => {
1101
+ const el = scrollRef.current
1102
+ if (!el) return undefined
1103
+ let observer = null
1104
+ try {
1105
+ if (typeof ResizeObserver === 'undefined') return undefined
1106
+ observer = new ResizeObserver(() => {
1107
+ if (!atBottomRef.current) return
1108
+ stickToBottom()
1109
+ })
1110
+ // 内容列是滚动容器的第一个子元素;容器自己也要看(窗口高度变化)。
1111
+ observer.observe(el.firstElementChild || el)
1112
+ observer.observe(el)
1113
+ } catch {
1114
+ return undefined
1115
+ }
1116
+ return () => observer.disconnect()
1117
+ }, [scrollRef, stickToBottom, ...deps])
1048
1118
  useEffect(() => {
1049
1119
  if (!atBottomRef.current) return undefined
1050
1120
  stickToBottom()
1051
1121
  const raf = requestAnimationFrame(stickToBottom)
1052
1122
  const timer = setTimeout(stickToBottom, 200)
1053
- return () => { cancelAnimationFrame(raf); clearTimeout(timer) }
1123
+ const late = setTimeout(stickToBottom, 800)
1124
+ return () => { cancelAnimationFrame(raf); clearTimeout(timer); clearTimeout(late) }
1054
1125
  }, deps)
1055
1126
  return { atBottom, atBottomRef, measureBottom, jumpToBottom }
1056
1127
  }
@@ -1843,7 +1914,9 @@ const Bubble = React.memo(function Bubble({ config, message, onMention, animate
1843
1914
  // 线在视口上方 = 上面还有没看过的。
1844
1915
  const lineAbove = Boolean(el && line && line.getBoundingClientRect().top < el.getBoundingClientRect().top + 4)
1845
1916
  // 点过一次就不再催:往下读时线会滑出视口上沿,以前会反复把提示亮出来(第 4 条)。
1846
- const next = lineAbove && !historyVisitedRef.current
1917
+ // 贴底时也不催:人已经看见最新的了;2026-11-17 第 2 条就是新消息比视口高、
1918
+ // 分割线被顶出上沿,于是"回到历史未读"又亮起来。
1919
+ const next = lineAbove && !historyVisitedRef.current && !atBottomRef.current
1847
1920
  if (next !== historyAboveRef.current) {
1848
1921
  historyAboveRef.current = next
1849
1922
  setHistoryAbove(next)
@@ -1963,6 +2036,13 @@ const Bubble = React.memo(function Bubble({ config, message, onMention, animate
1963
2036
  // 贴底 / 翻历史 / 回到底部:跟私聊页共用一套(见 useFollowTail)。
1964
2037
  const { atBottom, atBottomRef, measureBottom, jumpToBottom } = useFollowTail(scrollRef, [messages.length, tab, splash])
1965
2038
 
2039
+ // 贴底了就把"回到历史未读"收掉:人已经看见最新的了,留着只剩误导。
2040
+ // 2026-11-17 第 2 条:清完红点后来新消息,长消息把分割线顶出视口上沿,提示又亮。
2041
+ useEffect(() => {
2042
+ if (!atBottom) return
2043
+ if (historyAboveRef.current) { historyAboveRef.current = false; setHistoryAbove(false) }
2044
+ }, [atBottom])
2045
+
1966
2046
  // 「加载更早」之后保持眼睛原来的位置:上面新增了多少高度,就把滚动条往下推多少。
1967
2047
  useEffect(() => {
1968
2048
  const anchor = pendingScrollRef.current
@@ -2003,6 +2083,8 @@ const Bubble = React.memo(function Bubble({ config, message, onMention, animate
2003
2083
  const timer = setTimeout(() => {
2004
2084
  void markRead('group').then(() => {
2005
2085
  historyVisitedRef.current = false
2086
+ // 读完一批后分割线会挪到新位置:立刻重量,别等下一次滚动。
2087
+ measureHistory()
2006
2088
  refresh()
2007
2089
  // 面板读完一批,喊一声;侧边栏红点不用等下一轮轮询。
2008
2090
  window.dispatchEvent(new Event('dsh-group-read'))
@@ -2715,6 +2797,23 @@ const Bubble = React.memo(function Bubble({ config, message, onMention, animate
2715
2797
  const fileInputs = useRef({})
2716
2798
  const [avatarBusy, setAvatarBusy] = useState('')
2717
2799
 
2800
+ // 版本:进设置页先读当前版本;「检查更新」是显式动作(要联网,不自动跑)。
2801
+ const [versions, setVersions] = useState(null)
2802
+ const [updateState, setUpdateState] = useState(null)
2803
+ const [updateBusy, setUpdateBusy] = useState(false)
2804
+ useEffect(() => {
2805
+ void loadVersions()
2806
+ .then((data) => setVersions(data))
2807
+ .catch(() => setVersions({ error: '连不上宿主,读不到版本' }))
2808
+ }, [])
2809
+ const runCheckUpdate = () => {
2810
+ setUpdateBusy(true)
2811
+ void checkUpdates()
2812
+ .then((data) => setUpdateState(data))
2813
+ .catch((error) => setUpdateState({ error: String(error?.message ?? error) }))
2814
+ .finally(() => setUpdateBusy(false))
2815
+ }
2816
+
2718
2817
  const uploadAvatar = (member, file) => {
2719
2818
  if (!file) return
2720
2819
  if (!/^image\/(png|jpeg|webp)$/.test(file.type)) {
@@ -2884,6 +2983,22 @@ const Bubble = React.memo(function Bubble({ config, message, onMention, animate
2884
2983
  : '群里任何人说的话都算未读(除了你自己发的)。'),
2885
2984
  ),
2886
2985
 
2986
+ h(SettingsSection, { title: '版本', hint: '两个包必须一起装:宿主 + 面板。版本也一起看。' },
2987
+ h('div', { style: { display: 'flex', alignItems: 'center', gap: 10, marginTop: 8, flexWrap: 'wrap' } },
2988
+ h('div', { style: { flex: 1, minWidth: 220, fontSize: 13, lineHeight: '20px', color: 'var(--dsw-alias-label-primary)' } },
2989
+ versionLineOf(updateState ?? versions)),
2990
+ h('button', {
2991
+ onClick: runCheckUpdate,
2992
+ disabled: updateBusy,
2993
+ style: { ...smallBtnStyle, opacity: updateBusy ? 0.6 : 1 },
2994
+ }, updateBusy ? '检查中…' : '检查更新'),
2995
+ ),
2996
+ updateState?.checkedAt
2997
+ ? h('div', { style: { fontSize: 12, lineHeight: '18px', color: 'var(--dsw-alias-label-tertiary)', marginTop: 6 } },
2998
+ `检查时间:${String(updateState.checkedAt).replace('T', ' ').slice(0, 19)}`)
2999
+ : null,
3000
+ ),
3001
+
2887
3002
  h('div', {
2888
3003
  style: { marginTop: 16, fontSize: 12, lineHeight: '18px', color: 'var(--dsw-alias-label-tertiary)' },
2889
3004
  }, status || '改动会自动保存。侧边栏名称要刷新页面才变。'),
@@ -3603,7 +3718,7 @@ const Bubble = React.memo(function Bubble({ config, message, onMention, animate
3603
3718
  inject: ['slots'],
3604
3719
  apply(ctx) {
3605
3720
  // 一行"我跑的是哪一版"的自报,方便判断浏览器是不是还在用旧 bundle
3606
- console.info('[dsh-lil-whale-group-ui] client build v50 · history-no-flash:', Object.keys(MARKDOWN_LABELS).join(','))
3721
+ console.info('[dsh-lil-whale-group-ui] client build v51 · follow-tail-long:', Object.keys(MARKDOWN_LABELS).join(','))
3607
3722
  // 「正在回复…」那三个点的呼吸动画 + 过场转圈。只在浏览器里注入一次。
3608
3723
  if (typeof document !== 'undefined' && !document.getElementById('dsh-lil-whale-group-keyframes')) {
3609
3724
  const style = document.createElement('style')
package/lib/config.js CHANGED
@@ -1,126 +1,141 @@
1
- /**
2
- * 这台机器的假设,全从这里读。
3
- *
4
- * 为什么要有这个文件:代码里写死 `<她的家>` 之类的东西,等于"这段程序只在这台机器上
5
- * 成立"。打包给别人时最麻烦的不是改名,是这些路径 —— 装上以后跑不起来,报的还是一句
6
- * `ENOENT: no such file or directory`,看不出是谁的问题。
7
- *
8
- * 读法(优先级从高到低):
9
- * 1. 环境变量 `LIL_WHALE_CONFIG` 指向的 JSON 文件
10
- * 2. 仓库根目录的 `lil-whale.config.json`
11
- * 3. 一份"按标准布局"推出来的默认值(下面的 DEFAULTS)
12
- *
13
- * "标准布局"= 鱼塘根下 `app/` 是仓库、`homes/<键>/` 是鱼的家。所以别人克隆下来、
14
- * 把鱼塘摆成这个形状,不写配置文件也能跑;只有布局不一样时才需要那份 JSON。
15
- *
16
- * 注意仓库根是从**本文件的位置**往上数出来的,不是从进程 cwd 数出来的 —— 宿主的 cwd 是
17
- * "从哪儿启动的",我们的代码可能被 link 到别的 profile 目录里,cwd 靠不住。
18
- *
19
- * 字段命名(2026-11-14 改):每条鱼读的都是**自己**那份配置,所以 `self*` 指"这个进程
20
- * 服务的那条鱼"。旧的 `her*` / `whale*` 是单鱼时代的名字(第二条鱼出现后 `whaleProfile`
21
- * 在 fishball 的配置里只能填 `fishball`,读起来是错的),仍然接受,只作兼容别名。
22
- */
23
- import { existsSync, readFileSync } from 'node:fs'
24
- import { dirname, join, resolve } from 'node:path'
25
- import { fileURLToPath } from 'node:url'
26
-
27
- const HERE = dirname(fileURLToPath(import.meta.url))
28
- // lib/ → dsh-lil-whale-group/ → plugin/ → 仓库根
29
- const REPO_ROOT = resolve(HERE, '..', '..', '..')
30
-
31
- const DEFAULTS = {
32
- repoRoot: REPO_ROOT,
33
- // 鱼塘布局(2026-11-13 起):<pond>\app 是仓库,鱼在 <pond>\homes\<键>。
34
- // 配置丢了也不该指回旧布局(`<repo>\..\lil-whale` 那种),否则"默认值"会把新装的人带进老结构。
35
- selfHome: resolve(REPO_ROOT, '..', 'homes', 'fish'),
36
- selfWaker: join(REPO_ROOT, 'scripts', 'wake-fish.ps1'),
37
- wakeMetrics: join(REPO_ROOT, 'logs', 'wake-metrics.log'),
38
- pwshExe: process.platform === 'win32' ? 'pwsh.exe' : 'pwsh',
39
- leeCwd: REPO_ROOT,
40
- leeProfile: 'web',
41
- selfProfile: 'fish',
42
- // 这条鱼的进程开的端口。巡守要推门时敲的就是它;改端口必须同时改这里,否则巡守会去敲一扇没人的门。
43
- selfPort: 3082,
44
- }
45
-
46
- /** 旧名字 → 新名字。旧配置仍然能读,只是会被换成 `self*`。 */
47
- const LEGACY_KEYS = {
48
- herHome: 'selfHome',
49
- herDshHome: 'selfDshHome',
50
- herWaker: 'selfWaker',
51
- herPort: 'selfPort',
52
- whaleProfile: 'selfProfile',
53
- whaleCwd: 'selfCwd',
54
- }
55
-
56
- let cached = null
57
-
58
- export function configPath() {
59
- return process.env.LIL_WHALE_CONFIG || join(REPO_ROOT, 'lil-whale.config.json')
60
- }
61
-
62
- /** 派生字段(只由上面几个推出来,不许单独写死)。 */
63
- function derive(c) {
64
- // 先把旧名字抬成新名字(新名字优先)。
65
- const lifted = { ...c }
66
- for (const [oldKey, newKey] of Object.entries(LEGACY_KEYS)) {
67
- if (lifted[newKey] === undefined && lifted[oldKey] !== undefined) lifted[newKey] = lifted[oldKey]
68
- }
69
- const selfHome = lifted.selfHome
70
- // 共享区(pool)在她家之外:群、多成员账本都放这儿。
71
- // 为什么不在她家里:群是共享空间,不是她的私人物品;第二条鱼出现后,
72
- // 第二条的群文件写进第一条的家就是越界(Fabian 2026-11-12 拍板)。
73
- // 她家里留 Junction 指回 pool,所以她的路径一个字都不用改。
74
- // selfHome = <pond>\homes\<键> ⇒ 上两级才是 pond。
75
- const poolDir = lifted.poolDir || resolve(selfHome, '..', '..', 'pool')
76
- const out = {
77
- ...lifted,
78
- poolDir,
79
- poolStateDir: lifted.poolStateDir || join(poolDir, 'state'),
80
- // 私聊是「两个人之间的窗口」,不放进群目录:群目录是共享区里公开的那一半(Fabian 2026-11-12 拍板)。
81
- dmDir: lifted.dmDir || join(poolDir, 'dm'),
82
- // 名册:谁是谁、叫什么、哪条鱼、端口、爹是谁。多鱼之后这些不许再写死在代码里。
83
- membersFile: lifted.membersFile || join(poolDir, 'members.json'),
84
- selfPort: Number(lifted.selfPort) || 3082,
85
- groupDir: lifted.groupDir || join(poolDir, 'group'),
86
- selfDshHome: lifted.selfDshHome || join(selfHome, 'dsh-home'),
87
- selfCwd: lifted.selfCwd || selfHome,
88
- chatCwd: lifted.chatCwd || dirname(lifted.repoRoot),
89
- watchmanPidFile: lifted.watchmanPidFile || join(poolDir, 'state', 'watchman.pid'),
90
- }
91
- // 兼容别名:旧代码/旧脚本还在用 her* / whale*,给它们留一份只读映射。
92
- out.herHome = out.selfHome
93
- out.herDshHome = out.selfDshHome
94
- out.herWaker = out.selfWaker
95
- out.herPort = out.selfPort
96
- out.whaleProfile = out.selfProfile
97
- out.whaleCwd = out.selfCwd
98
- return out
99
- }
100
-
101
- /**
102
- * 读一次,缓存起来(进程生命周期内不变 —— 改配置要重启,这是有意的:
103
- * 热改路径会让"这个进程到底在读哪份文件"变成一个没人答得上来的问题)。
104
- */
105
- export function config() {
106
- if (cached) return cached
107
- const path = configPath()
108
- let raw = {}
109
- let error = null
110
- if (existsSync(path)) {
111
- try {
112
- raw = JSON.parse(readFileSync(path, 'utf8'))
113
- } catch (e) {
114
- // 配置写坏了要说出来,不能安静地用默认值跑 —— 那会让人以为自己改对了
115
- error = `config 读取失败(${path}):${e.message}`
116
- }
117
- }
118
- cached = { ...derive({ ...DEFAULTS, ...raw }), _path: path, _exists: existsSync(path), _error: error }
119
- return cached
120
- }
121
-
122
- /** 给启动痕迹用的短摘要:哪份配置、这条鱼的家在哪儿。 */
123
- export function configSummary() {
124
- const c = config()
125
- return { path: c._path, exists: c._exists, error: c._error, selfHome: c.selfHome, groupDir: c.groupDir }
126
- }
1
+ /**
2
+ * 这台机器的假设,全从这里读。
3
+ *
4
+ * 为什么要有这个文件:代码里写死 `<她的家>` 之类的东西,等于"这段程序只在这台机器上
5
+ * 成立"。打包给别人时最麻烦的不是改名,是这些路径 —— 装上以后跑不起来,报的还是一句
6
+ * `ENOENT: no such file or directory`,看不出是谁的问题。
7
+ *
8
+ * 读法(优先级从高到低):
9
+ * 1. 环境变量 `LIL_WHALE_CONFIG` 指向的 JSON 文件
10
+ * 2. 仓库根目录的 `lil-whale.config.json`
11
+ * 3. 一份"按标准布局"推出来的默认值(下面的 DEFAULTS)
12
+ *
13
+ * "标准布局"= 鱼塘根下 `app/` 是仓库、`homes/<键>/` 是鱼的家。所以别人克隆下来、
14
+ * 把鱼塘摆成这个形状,不写配置文件也能跑;只有布局不一样时才需要那份 JSON。
15
+ *
16
+ * 注意仓库根是从**本文件的位置**往上数出来的,不是从进程 cwd 数出来的 —— 宿主的 cwd 是
17
+ * "从哪儿启动的",我们的代码可能被 link 到别的 profile 目录里,cwd 靠不住。
18
+ *
19
+ * 字段命名(2026-11-14 改):每条鱼读的都是**自己**那份配置,所以 `self*` 指"这个进程
20
+ * 服务的那条鱼"。旧的 `her*` / `whale*` 是单鱼时代的名字(第二条鱼出现后 `whaleProfile`
21
+ * 在 fishball 的配置里只能填 `fishball`,读起来是错的),仍然接受,只作兼容别名。
22
+ */
23
+ import { existsSync, readFileSync } from 'node:fs'
24
+ import { dirname, join, resolve } from 'node:path'
25
+ import { fileURLToPath } from 'node:url'
26
+
27
+ const HERE = dirname(fileURLToPath(import.meta.url))
28
+ // lib/ → dsh-lil-whale-group/ → plugin/ → 仓库根
29
+ const REPO_ROOT = resolve(HERE, '..', '..', '..')
30
+
31
+ const DEFAULTS = {
32
+ repoRoot: REPO_ROOT,
33
+ // 鱼塘布局(2026-11-13 起):<pond>\app 是仓库,鱼在 <pond>\homes\<键>。
34
+ // 配置丢了也不该指回旧布局(`<repo>\..\lil-whale` 那种),否则"默认值"会把新装的人带进老结构。
35
+ selfHome: resolve(REPO_ROOT, '..', 'homes', 'fish'),
36
+ selfWaker: join(REPO_ROOT, 'scripts', 'wake-fish.ps1'),
37
+ wakeMetrics: join(REPO_ROOT, 'logs', 'wake-metrics.log'),
38
+ pwshExe: process.platform === 'win32' ? 'pwsh.exe' : 'pwsh',
39
+ leeCwd: REPO_ROOT,
40
+ leeProfile: 'web',
41
+ selfProfile: 'fish',
42
+ // 这条鱼的进程开的端口。巡守要推门时敲的就是它;改端口必须同时改这里,否则巡守会去敲一扇没人的门。
43
+ selfPort: 3082,
44
+ }
45
+
46
+ /** 旧名字 → 新名字。旧配置仍然能读,只是会被换成 `self*`。 */
47
+ const LEGACY_KEYS = {
48
+ herHome: 'selfHome',
49
+ herDshHome: 'selfDshHome',
50
+ herWaker: 'selfWaker',
51
+ herPort: 'selfPort',
52
+ whaleProfile: 'selfProfile',
53
+ whaleCwd: 'selfCwd',
54
+ }
55
+
56
+ let cached = null
57
+
58
+ export function configPath() {
59
+ return process.env.LIL_WHALE_CONFIG || join(REPO_ROOT, 'lil-whale.config.json')
60
+ }
61
+
62
+ /**
63
+ * 配置从哪来。三种状态别混:(r242)
64
+ * env / env-missing / repo / default;env-missing 是配置错误,不是"没有配置"。
65
+ */
66
+ function configSourceOf(path) {
67
+ const fromEnv = Boolean(process.env.LIL_WHALE_CONFIG)
68
+ if (fromEnv) return existsSync(path) ? 'env' : 'env-missing'
69
+ return existsSync(path) ? 'repo' : 'default'
70
+ }
71
+
72
+ /** 派生字段(只由上面几个推出来,不许单独写死)。 */
73
+ function derive(c) {
74
+ // 先把旧名字抬成新名字(新名字优先)。
75
+ const lifted = { ...c }
76
+ for (const [oldKey, newKey] of Object.entries(LEGACY_KEYS)) {
77
+ if (lifted[newKey] === undefined && lifted[oldKey] !== undefined) lifted[newKey] = lifted[oldKey]
78
+ }
79
+ const selfHome = lifted.selfHome
80
+ // 共享区(pool)在她家之外:群、多成员账本都放这儿。
81
+ // 为什么不在她家里:群是共享空间,不是她的私人物品;第二条鱼出现后,
82
+ // 第二条的群文件写进第一条的家就是越界(Fabian 2026-11-12 拍板)。
83
+ // 她家里留 Junction 指回 pool,所以她的路径一个字都不用改。
84
+ // selfHome = <pond>\homes\<键> ⇒ 上两级才是 pond。
85
+ const poolDir = lifted.poolDir || resolve(selfHome, '..', '..', 'pool')
86
+ const out = {
87
+ ...lifted,
88
+ poolDir,
89
+ poolStateDir: lifted.poolStateDir || join(poolDir, 'state'),
90
+ // 私聊是「两个人之间的窗口」,不放进群目录:群目录是共享区里公开的那一半(Fabian 2026-11-12 拍板)。
91
+ dmDir: lifted.dmDir || join(poolDir, 'dm'),
92
+ // 名册:谁是谁、叫什么、哪条鱼、端口、爹是谁。多鱼之后这些不许再写死在代码里。
93
+ membersFile: lifted.membersFile || join(poolDir, 'members.json'),
94
+ selfPort: Number(lifted.selfPort) || 3082,
95
+ groupDir: lifted.groupDir || join(poolDir, 'group'),
96
+ selfDshHome: lifted.selfDshHome || join(selfHome, 'dsh-home'),
97
+ selfCwd: lifted.selfCwd || selfHome,
98
+ chatCwd: lifted.chatCwd || dirname(lifted.repoRoot),
99
+ watchmanPidFile: lifted.watchmanPidFile || join(poolDir, 'state', 'watchman.pid'),
100
+ }
101
+ // 兼容别名:旧代码/旧脚本还在用 her* / whale*,给它们留一份只读映射。
102
+ out.herHome = out.selfHome
103
+ out.herDshHome = out.selfDshHome
104
+ out.herWaker = out.selfWaker
105
+ out.herPort = out.selfPort
106
+ out.whaleProfile = out.selfProfile
107
+ out.whaleCwd = out.selfCwd
108
+ return out
109
+ }
110
+
111
+ /**
112
+ * 读一次,缓存起来(进程生命周期内不变 —— 改配置要重启,这是有意的:
113
+ * 热改路径会让"这个进程到底在读哪份文件"变成一个没人答得上来的问题)。
114
+ */
115
+ export function config() {
116
+ if (cached) return cached
117
+ const path = configPath()
118
+ let raw = {}
119
+ let error = null
120
+ if (existsSync(path)) {
121
+ try {
122
+ raw = JSON.parse(readFileSync(path, 'utf8'))
123
+ } catch (e) {
124
+ // 配置写坏了要说出来,不能安静地用默认值跑 —— 那会让人以为自己改对了
125
+ error = `config 读取失败(${path}):${e.message}`
126
+ }
127
+ }
128
+ const source = configSourceOf(path)
129
+ if (source === 'env-missing' && !error) {
130
+ // 环境变量给了 = "我要用这一份";文件不在是配置错误,不能安静地用默认值继续跑。
131
+ error = `LIL_WHALE_CONFIG 指向的文件不存在:${path}`
132
+ }
133
+ cached = { ...derive({ ...DEFAULTS, ...raw }), _path: path, _exists: existsSync(path), _error: error, _source: source }
134
+ return cached
135
+ }
136
+
137
+ /** 给启动痕迹用的短摘要:哪份配置、这条鱼的家在哪儿。 */
138
+ export function configSummary() {
139
+ const c = config()
140
+ return { path: c._path, source: c._source, exists: c._exists, error: c._error, selfHome: c.selfHome, groupDir: c.groupDir }
141
+ }
package/lib/index.js CHANGED
@@ -10,6 +10,8 @@ import { join } from 'node:path'
10
10
  import { createHash } from 'node:crypto'
11
11
  import { spawn } from 'node:child_process'
12
12
  import { Socket } from 'node:net'
13
+ import { fileURLToPath } from 'node:url'
14
+ import { createRequire } from 'node:module'
13
15
  import { config } from './config.js'
14
16
 
15
17
  export const name = '@fabianactor/dsh-lil-whale-group-ui'
@@ -56,6 +58,61 @@ const IMAGE_EXT = { png: 'image/png', jpg: 'image/jpeg', webp: 'image/webp', gif
56
58
  const IMAGE_FMT = 2
57
59
  const IMAGE_ALGO = 'sha256'
58
60
 
61
+ // 版本:设置页要显示「当前版本」并检查 npm 上的最新版。
62
+ // 当前版本从两个包自己的 package.json 读(ui 就是自己;host 走模块解析,
63
+ // 解析不到再按同 scope 的兄弟目录找)——不写死数字,免得代码和 package.json 各说各话。
64
+ const UI_PACKAGE = JSON.parse(readFileSync(fileURLToPath(new URL('../package.json', import.meta.url)), 'utf8'))
65
+ const HOST_PACKAGE_NAME = '@fabianactor/dsh-lil-whale-group'
66
+
67
+ function hostPackageVersion() {
68
+ try {
69
+ const req = createRequire(import.meta.url)
70
+ const file = req.resolve(HOST_PACKAGE_NAME + '/package.json')
71
+ return JSON.parse(readFileSync(file, 'utf8')).version ?? null
72
+ } catch {
73
+ try {
74
+ return JSON.parse(readFileSync(fileURLToPath(new URL('../../dsh-lil-whale-group/package.json', import.meta.url)), 'utf8')).version ?? null
75
+ } catch {
76
+ return null
77
+ }
78
+ }
79
+ }
80
+
81
+ function versionState() {
82
+ return {
83
+ host: { name: HOST_PACKAGE_NAME, current: hostPackageVersion() },
84
+ ui: { name: UI_PACKAGE.name, current: UI_PACKAGE.version ?? null },
85
+ }
86
+ }
87
+
88
+ /** 只比 x.y.z 的数字段;预发布标签(-rc.1)忽略——给人看的是版本,不是 semver 全集。 */
89
+ function newerThan(latest, current) {
90
+ if (!latest || !current) return null
91
+ const a = String(latest).split('-')[0].split('.').map((n) => Number(n) || 0)
92
+ const b = String(current).split('-')[0].split('.').map((n) => Number(n) || 0)
93
+ for (let i = 0; i < 3; i += 1) {
94
+ if ((a[i] ?? 0) > (b[i] ?? 0)) return true
95
+ if ((a[i] ?? 0) < (b[i] ?? 0)) return false
96
+ }
97
+ return false
98
+ }
99
+
100
+ async function latestOnNpm(packageName) {
101
+ const controller = new AbortController()
102
+ const timer = setTimeout(() => controller.abort(), 8000)
103
+ try {
104
+ const response = await fetch(`https://registry.npmjs.org/${packageName.replace('/', '%2F')}/latest`, {
105
+ signal: controller.signal,
106
+ headers: { accept: 'application/json' },
107
+ })
108
+ if (!response.ok) throw new Error(`HTTP ${response.status}`)
109
+ const data = await response.json()
110
+ return typeof data?.version === 'string' ? data.version : null
111
+ } finally {
112
+ clearTimeout(timer)
113
+ }
114
+ }
115
+
59
116
  /**
60
117
  * 读不到的图片必须留痕,否则"没有图"和"图丢了"看起来一样(小肥鱼的原话:
61
118
  * 校验的价值不在拦住坏路径,在让坏路径有痕迹)。
@@ -877,6 +934,44 @@ export function apply(ctx) {
877
934
  },
878
935
  }))
879
936
 
937
+ // 版本:当前版本随时能看;「检查更新」才去问 npm。
938
+ // 网络不通要说清楚,不能装成"已是最新"——那和真的检查过长得一样(§60)。
939
+ disposers.push(ctx.webServer.register({
940
+ kind: 'exact',
941
+ path: '/group/api/version',
942
+ handler(req, res) {
943
+ if (req.method !== 'GET') {
944
+ sendJson(res, 405, { error: 'method-not-allowed' })
945
+ return
946
+ }
947
+ sendJson(res, 200, versionState())
948
+ },
949
+ }))
950
+
951
+ disposers.push(ctx.webServer.register({
952
+ kind: 'exact',
953
+ path: '/group/api/check-update',
954
+ async handler(req, res) {
955
+ if (!guardWrite(req, res, '/group/api/check-update')) return
956
+ if (req.method !== 'POST') {
957
+ sendJson(res, 405, { error: 'method-not-allowed' })
958
+ return
959
+ }
960
+ const base = versionState()
961
+ const result = { checkedAt: new Date().toISOString(), host: { ...base.host }, ui: { ...base.ui } }
962
+ for (const side of ['host', 'ui']) {
963
+ try {
964
+ const latest = await latestOnNpm(result[side].name)
965
+ result[side].latest = latest
966
+ result[side].updateAvailable = newerThan(latest, result[side].current)
967
+ } catch (error) {
968
+ result[side].error = String(error?.message ?? error)
969
+ }
970
+ }
971
+ sendJson(res, 200, result)
972
+ },
973
+ }))
974
+
880
975
  /**
881
976
  * 头像照片:读一张、换一张、去掉。
882
977
  *
package/locale/en.json ADDED
@@ -0,0 +1 @@
1
+ {"meta":{"title":"lil-whale panel","description":"Sidebar panel for the lil-whale group: group chat, DMs, unread badges, images and a pond page that starts and stops each agent. Requires the host package @fabianactor/dsh-lil-whale-group."}}
package/locale/zh.json ADDED
@@ -0,0 +1 @@
1
+ {"meta":{"title":"小小肥鱼 · 面板","description":"侧边栏面板:群聊、私聊、未读红点、图片,以及开关每条鱼的鱼塘页。需同时安装宿主包 @fabianactor/dsh-lil-whale-group。"}}
package/package.json CHANGED
@@ -1,46 +1,51 @@
1
- {
2
- "name": "@fabianactor/dsh-lil-whale-group-ui",
3
- "version": "1.8.15",
4
- "type": "module",
5
- "description": "群聊页面:侧边栏一个图标,点开是三条鱼的群(读写 lil-whale\\group\\messages.jsonl)",
6
- "author": "Fabian",
7
- "license": "MIT",
8
- "repository": {
9
- "type": "git",
10
- "url": "git+https://github.com/FabianActor/dsh-lil-whale.git",
11
- "directory": "plugin/dsh-lil-whale-group-ui"
12
- },
13
- "keywords": [
14
- "dsh",
15
- "dsh-plugin",
16
- "deepseek-harness",
17
- "group-chat",
18
- "web-ui"
19
- ],
20
- "engines": {
21
- "dsh": ">=0.2.2-rc.1"
22
- },
23
- "publishConfig": {
24
- "access": "public"
25
- },
26
- "exports": {
27
- ".": "./lib/index.js",
28
- "./client": "./lib/client.js"
29
- },
30
- "files": [
31
- "lib/*.js",
32
- "cordis.patch.yml"
33
- ],
34
- "dsh": {
35
- "bundle": {
36
- "patch": "./cordis.patch.yml"
37
- },
38
- "client": {
39
- "platform": "web",
40
- "immediately": true,
41
- "inject": [
42
- "@deepseek-ai/dsh-client-ui-primitives"
43
- ]
44
- }
45
- }
46
- }
1
+ {
2
+ "name": "@fabianactor/dsh-lil-whale-group-ui",
3
+ "version": "1.10.0",
4
+ "type": "module",
5
+ "description": "群聊页面:侧边栏一个图标,点开是三条鱼的群(读写 lil-whale\\group\\messages.jsonl)",
6
+ "author": "Fabian",
7
+ "license": "MIT",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/FabianActor/dsh-lil-whale.git",
11
+ "directory": "plugin/dsh-lil-whale-group-ui"
12
+ },
13
+ "keywords": [
14
+ "dsh",
15
+ "dsh-plugin",
16
+ "deepseek-harness",
17
+ "group-chat",
18
+ "web-ui"
19
+ ],
20
+ "engines": {
21
+ "dsh": ">=0.2.2-rc.1"
22
+ },
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "exports": {
27
+ ".": "./lib/index.js",
28
+ "./client": "./lib/client.js",
29
+ "./package.json": "./package.json",
30
+ "./locale/*": "./locale/*"
31
+ },
32
+ "files": [
33
+ "lib/*.js",
34
+ "cordis.patch.yml",
35
+ "icon.png",
36
+ "locale"
37
+ ],
38
+ "dsh": {
39
+ "bundle": {
40
+ "patch": "./cordis.patch.yml"
41
+ },
42
+ "client": {
43
+ "platform": "web",
44
+ "immediately": true,
45
+ "inject": [
46
+ "@deepseek-ai/dsh-client-ui-primitives"
47
+ ]
48
+ }
49
+ },
50
+ "icon": "icon.png"
51
+ }