@fabianactor/dsh-lil-whale-group-ui 1.10.0 → 1.11.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/lib/client.js CHANGED
@@ -675,11 +675,42 @@ function insertNewline(el, value, setValue) {
675
675
  growTextarea(el)
676
676
  })
677
677
  }
678
- const Bubble = React.memo(function Bubble({ config, message, onMention, animate = false }) {
678
+ // 点消息头上的行号复制引用:`群 #1763` / `私聊 fabian__lee2 #3`。
679
+ // 优先用 Clipboard API;不安全的上下文(非 https/非 localhost)会没有这个对象,
680
+ // 落到老办法(临时 textarea + execCommand),失败就返回 false,让调用方不显示「已复制」。
681
+ async function copyToClipboard(text) {
682
+ try {
683
+ if (navigator.clipboard && navigator.clipboard.writeText) {
684
+ await navigator.clipboard.writeText(text)
685
+ return true
686
+ }
687
+ } catch {
688
+ // 继续走兜底
689
+ }
690
+ try {
691
+ const area = document.createElement('textarea')
692
+ area.value = text
693
+ area.setAttribute('readonly', '')
694
+ area.style.position = 'fixed'
695
+ area.style.top = '-1000px'
696
+ area.style.opacity = '0'
697
+ document.body.appendChild(area)
698
+ area.select()
699
+ const ok = document.execCommand('copy')
700
+ area.remove()
701
+ return ok
702
+ } catch {
703
+ return false
704
+ }
705
+ }
706
+
707
+ const Bubble = React.memo(function Bubble({ config, message, onMention, animate = false, citePrefix = '' }) {
679
708
  // 只在挂载时决定「要不要动画」:否则后续每次重渲染都会让老消息重新弹一遍。
680
709
  const animateOnMount = useRef(animate).current
681
710
  // 点图片打开官方看图器(大图、点外面关)。
682
711
  const [previewIndex, setPreviewIndex] = useState(-1)
712
+ // 行号点一下复制引用;1.2 秒内显示「已复制」当回执。
713
+ const [lineCopied, setLineCopied] = useState(false)
683
714
  const images = Array.isArray(message.images) ? message.images : (message.image ? [message.image] : [])
684
715
  const imageSrcs = images.map((image) => imageUrlOf(image))
685
716
  const humanId = config?.humanId ?? 'fabian'
@@ -689,6 +720,18 @@ const Bubble = React.memo(function Bubble({ config, message, onMention, animate
689
720
  const targetTo = message.toSeat ? `${message.to}@${message.toSeat}` : message.to
690
721
  const target = message.to && message.to !== 'all' ? ` → ${targetName(config, targetTo)}` : ''
691
722
  const time = formatStamp(message.ts)
723
+ // 行号:引用地址。群是 messages.jsonl 的行,私聊是 pool\dm\<pair>.jsonl 的行。
724
+ // 文件是 append-only,行号不会变;点一下复制成别人能直接引用的形状。
725
+ const lineNo = typeof message.line === 'number' && message.line > 0 ? message.line : 0
726
+ const cite = lineNo > 0 ? `${citePrefix} #${lineNo}`.trim() : ''
727
+ const copyCite = () => {
728
+ if (!cite) return
729
+ copyToClipboard(cite).then((ok) => {
730
+ if (!ok) return
731
+ setLineCopied(true)
732
+ window.setTimeout(() => setLineCopied(false), 1200)
733
+ })
734
+ }
692
735
  return h(React.Fragment, null,
693
736
  h('div', {
694
737
  style: {
@@ -719,7 +762,15 @@ const Bubble = React.memo(function Bubble({ config, message, onMention, animate
719
762
  display: 'flex', alignItems: 'baseline', gap: 6,
720
763
  fontSize: 12, color: 'var(--dsw-alias-label-tertiary)',
721
764
  },
722
- }, h('span', null, who + target), h('span', null, time)),
765
+ },
766
+ h('span', null, who + target),
767
+ h('span', null, time),
768
+ lineNo > 0 ? h('span', {
769
+ key: 'line',
770
+ title: lineCopied ? '已复制' : `点击复制引用:${cite}`,
771
+ onClick: copyCite,
772
+ style: { cursor: 'pointer', fontSize: 11, color: 'var(--dsw-alias-label-caption)', userSelect: 'none' },
773
+ }, lineCopied ? '已复制' : `#${lineNo}`) : null),
723
774
  h('div', {
724
775
  style: {
725
776
  padding: '8px 12px', borderRadius: 'var(--dsw-radius-lg, 12px)',
@@ -1554,7 +1605,12 @@ const Bubble = React.memo(function Bubble({ config, message, onMention, animate
1554
1605
  // 同群聊:打字不重排私聊历史。
1555
1606
  const dmListNode = useMemo(
1556
1607
  () => withDivider(messages, String(seenDm[activePeer] ?? ''), (message, index) => h(Bubble, {
1557
- key: `${message.ts}-${index}`, config, message, animate: animateRef.current,
1608
+ key: `${message.ts}-${index}`,
1609
+ config,
1610
+ message,
1611
+ animate: animateRef.current,
1612
+ // 私聊引用要写清是哪一本:pool\dm\<a>__<b>.jsonl,键按字典序排(与文件命名同规则)。
1613
+ citePrefix: `私聊 ${[(config?.humanId ?? 'fabian'), activePeer].sort().join('__')}`,
1558
1614
  })),
1559
1615
  [messages, seenDm, activePeer, config],
1560
1616
  )
@@ -2252,6 +2308,7 @@ const Bubble = React.memo(function Bubble({ config, message, onMention, animate
2252
2308
  message,
2253
2309
  animate: animateRef.current,
2254
2310
  onMention: mentionTo,
2311
+ citePrefix: '群',
2255
2312
  }), dividerRef)
2256
2313
  if (visibleStart === 0) return nodes
2257
2314
  const earlier = h(
@@ -3718,7 +3775,7 @@ const Bubble = React.memo(function Bubble({ config, message, onMention, animate
3718
3775
  inject: ['slots'],
3719
3776
  apply(ctx) {
3720
3777
  // 一行"我跑的是哪一版"的自报,方便判断浏览器是不是还在用旧 bundle
3721
- console.info('[dsh-lil-whale-group-ui] client build v51 · follow-tail-long:', Object.keys(MARKDOWN_LABELS).join(','))
3778
+ console.info('[dsh-lil-whale-group-ui] client build v52 · line-cite:', Object.keys(MARKDOWN_LABELS).join(','))
3722
3779
  // 「正在回复…」那三个点的呼吸动画 + 过场转圈。只在浏览器里注入一次。
3723
3780
  if (typeof document !== 'undefined' && !document.getElementById('dsh-lil-whale-group-keyframes')) {
3724
3781
  const style = document.createElement('style')
package/lib/index.js CHANGED
@@ -13,6 +13,7 @@ import { Socket } from 'node:net'
13
13
  import { fileURLToPath } from 'node:url'
14
14
  import { createRequire } from 'node:module'
15
15
  import { config } from './config.js'
16
+ import { parseMessageLines } from './messages-core.js'
16
17
 
17
18
  export const name = '@fabianactor/dsh-lil-whale-group-ui'
18
19
  export const inject = ['webServer', 'agents']
@@ -474,31 +475,9 @@ function lastTsOf(file) {
474
475
 
475
476
  function readMessages(file = MESSAGES) {
476
477
  if (!existsSync(file)) return []
477
- const out = []
478
- for (const line of readFileSync(file, 'utf8').split(/\r?\n/)) {
479
- const text = line.trim()
480
- if (!text) continue
481
- try {
482
- const record = JSON.parse(text)
483
- // 投影要带全:面板靠这些字段画图、画「→ 某人的哪一段」、判断私聊/群。早先只留了
484
- // ts/from/to/text/kind,结果她发的图在面板里根本不显示 —— 记录里有、列表里没有。
485
- out.push({
486
- ts: record.ts,
487
- from: record.from,
488
- to: record.to,
489
- text: record.text,
490
- kind: record.kind ?? 'say',
491
- ...(record.s ? { s: record.s } : {}),
492
- ...(record.channel ? { channel: record.channel } : {}),
493
- ...(record.toSeat ? { toSeat: record.toSeat } : {}),
494
- ...(record.image ? { image: record.image } : {}),
495
- ...(Array.isArray(record.images) && record.images.length > 0 ? { images: record.images } : {}),
496
- })
497
- } catch {
498
- // 半截行(另一个进程正在写)——跳过,下一次轮询就整了
499
- }
500
- }
501
- return out
478
+ // 投影与行号在 lib/messages-core.js:行号是物理行号(空行/半截行也算),
479
+ // 它是面板上 #1763 这个引用地址的来源(r328)。
480
+ return parseMessageLines(readFileSync(file, 'utf8'))
502
481
  }
503
482
 
504
483
  function readBody(req, limit = 256 * 1024) {
@@ -0,0 +1,43 @@
1
+ // 消息文件的投影:把 JSONL 变成面板能画的对象,同时带上**物理行号**。
2
+ //
3
+ // 为什么行号要在这里定:面板上的 `#1763` 是引用地址,指的是 messages.jsonl /
4
+ // pool\dm\<a>__<b>.jsonl 的第 1763 行(两个文件都是 append-only,行号不会变)。
5
+ // 行号必须按"读到的第几行"算,包含空行与半截行 —— 否则引用会随文件里的空行错位。
6
+ //
7
+ // 抽出成纯函数(2026-11-18,r328)是为了能直接测:以前这段埋在 web 路由的文件里,
8
+ // 只靠静态断言证明"代码里写了这件事",测不到"空行/坏行时行号对不对"。
9
+
10
+ export function projectMessage(record) {
11
+ // 投影要带全:面板靠这些字段画图、画「→ 某人的哪一段」、判断私聊/群。早先只留了
12
+ // ts/from/to/text/kind,结果她发的图在面板里根本不显示 —— 记录里有、列表里没有。
13
+ const out = {
14
+ ts: record.ts,
15
+ from: record.from,
16
+ to: record.to,
17
+ text: record.text,
18
+ kind: record.kind ?? 'say',
19
+ }
20
+ if (record.s) out.s = record.s
21
+ if (record.channel) out.channel = record.channel
22
+ if (record.toSeat) out.toSeat = record.toSeat
23
+ if (record.image) out.image = record.image
24
+ if (Array.isArray(record.images) && record.images.length > 0) out.images = record.images
25
+ return out
26
+ }
27
+
28
+ export function parseMessageLines(text) {
29
+ const out = []
30
+ let lineNo = 0
31
+ for (const line of String(text).split(/\r?\n/)) {
32
+ lineNo += 1
33
+ const raw = line.trim()
34
+ if (!raw) continue
35
+ try {
36
+ const record = JSON.parse(raw)
37
+ out.push({ line: lineNo, ...projectMessage(record) })
38
+ } catch {
39
+ // 半截行(另一个进程正在写)——跳过,下一次轮询就整了;行号照旧往前数。
40
+ }
41
+ }
42
+ return out
43
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabianactor/dsh-lil-whale-group-ui",
3
- "version": "1.10.0",
3
+ "version": "1.11.0",
4
4
  "type": "module",
5
5
  "description": "群聊页面:侧边栏一个图标,点开是三条鱼的群(读写 lil-whale\\group\\messages.jsonl)",
6
6
  "author": "Fabian",