dsh-deepseek-webchat 0.4.10 → 0.4.11

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
@@ -104,7 +104,7 @@ window.__ModuleLoader__.load({
104
104
  * plus laying out all of them blocks the main thread: 73 ms for 555, mostly
105
105
  * the forced layout. The list opens on the newest few, which is what a
106
106
  * person actually picks from, and older rows are loaded a page at a time
107
- * from the top. Selection is by `seq`, so the bulk actions still cover the
107
+ * from the top. Selection is by row id, so the bulk actions still cover the
108
108
  * whole session rather than only what is mounted.
109
109
  */
110
110
  const LIST_PAGE_SIZE = 10
@@ -598,9 +598,22 @@ window.__ModuleLoader__.load({
598
598
  '.dswc-muted{color:var(--dsw-alias-label-tertiary,#adb2b8);font-size:11px}',
599
599
  '.dswc-more{position:sticky;top:0;display:flex;align-items:center;gap:8px;padding:6px 8px;background:var(--dsw-alias-bg-layer-1,#fff);border-bottom:1px solid var(--dsw-alias-border-l4,rgba(128,128,128,.25))}',
600
600
  '.dswc-list{flex:1 1 auto;min-height:60px;overflow:auto;border:1px solid var(--dsw-alias-border-l4,rgba(128,128,128,.25));border-radius:var(--dsw-radius-md,12px)}',
601
- '.dswc-row{display:flex;gap:6px;padding:6px 8px;cursor:pointer;border-bottom:1px solid var(--dsw-alias-border-l4,rgba(128,128,128,.15))}',
601
+ '.dswc-row{display:flex;align-items:flex-start;gap:6px;padding:6px 8px;cursor:pointer;border-bottom:1px solid var(--dsw-alias-border-l4,rgba(128,128,128,.15));user-select:none;-webkit-user-select:none;outline:none}',
602
602
  '.dswc-row:last-child{border-bottom:0}',
603
603
  '.dswc-row:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.08))}',
604
+ '.dswc-row:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary,#4d6bfe);outline-offset:-2px}',
605
+ // The tick box. It is drawn rather than inherited: a native checkbox
606
+ // inside a label made one click travel through the label's
607
+ // forwarding rule, and its size/ink came from whatever the shell's
608
+ // global form styles happened to be.
609
+ '.dswc-box{flex:none;box-sizing:border-box;width:13px;height:13px;margin-top:2px;position:relative;border:1px solid var(--dsw-alias-border-l4,rgba(128,128,128,.55));border-radius:3px;background:transparent}',
610
+ '.dswc-row:hover .dswc-box{border-color:var(--dsw-alias-label-secondary,#cfd3d6)}',
611
+ '.dswc-row[aria-checked="true"] .dswc-box{border-color:var(--dsw-alias-state-business-primary,#4d6bfe);background:var(--dsw-alias-state-business-primary,#4d6bfe)}',
612
+ '.dswc-row[aria-checked="true"] .dswc-box::after{content:"";position:absolute;left:3.5px;top:0.5px;width:4px;height:8px;border:solid #fff;border-width:0 1.5px 1.5px 0;transform:rotate(45deg)}',
613
+ '.dswc-row[aria-checked="true"]{background:rgba(77,107,254,.08)}',
614
+ '.dswc-row[aria-checked="true"]{background:color-mix(in srgb,var(--dsw-alias-state-business-primary,#4d6bfe) 10%,transparent)}',
615
+ '.dswc-row[aria-checked="true"]:hover{background:rgba(77,107,254,.14)}',
616
+ '.dswc-row[aria-checked="true"]:hover{background:color-mix(in srgb,var(--dsw-alias-state-business-primary,#4d6bfe) 16%,transparent)}',
604
617
  // The row marker is an icon from the shell's own set plus a short
605
618
  // word, inside a fixed-width column so the text of every row starts
606
619
  // at the same place however long the label is.
@@ -1658,6 +1671,42 @@ window.__ModuleLoader__.load({
1658
1671
  return ChatBubbleGlyph(props)
1659
1672
  }
1660
1673
 
1674
+ /**
1675
+ * Which way the browser should paint a native control's own surfaces.
1676
+ *
1677
+ * The shell paints a dark app without declaring `color-scheme`, so the
1678
+ * popup of a native `<select>` is drawn light (browser default) while
1679
+ * its option text inherits the app's near-white ink: the list reads as
1680
+ * blank, and a row only becomes legible while the pointer is over it and
1681
+ * the hover highlight paints something behind the text. `color-scheme`
1682
+ * is exactly the hint that makes the popup and the ink agree, and the
1683
+ * surface the control actually sits on is the honest source for it —
1684
+ * no guessing at the shell's theme attribute.
1685
+ *
1686
+ * @param element - any node inside the pane.
1687
+ * @returns `'dark'` or `'light'`.
1688
+ */
1689
+ function controlScheme(element) {
1690
+ const osDark = typeof matchMedia === 'function'
1691
+ && matchMedia('(prefers-color-scheme: dark)').matches
1692
+ const fallback = osDark ? 'dark' : 'light'
1693
+ let node = element
1694
+ while (node !== null && node !== undefined && typeof node !== 'string') {
1695
+ const match = /rgba?\(([^)]+)\)/.exec(String(window.getComputedStyle(node).backgroundColor))
1696
+ if (match !== null) {
1697
+ const [r, g, b, a = 1] = match[1].split(',').map((part) => Number.parseFloat(part))
1698
+ if ([r, g, b, a].every((part) => Number.isFinite(part)) && a > 0.4) {
1699
+ // Perceived luminance. The exact weights do not matter; only
1700
+ // which side of half the surface falls on does.
1701
+ const luma = (0.2126 * r + 0.7152 * g + 0.0722 * b) / 255
1702
+ return luma > 0.5 ? 'light' : 'dark'
1703
+ }
1704
+ }
1705
+ node = node.parentElement ?? null
1706
+ }
1707
+ return fallback
1708
+ }
1709
+
1661
1710
  /**
1662
1711
  * The tab body: a toolbar, and either the picker or the measured guest area.
1663
1712
  * @param props - standard slot props plus the injected session id.
@@ -1686,6 +1735,11 @@ window.__ModuleLoader__.load({
1686
1735
  const [advanced, setAdvanced] = React.useState(false)
1687
1736
  const [preamble, setPreamble] = React.useState(true)
1688
1737
  const [lastN, setLastN] = React.useState(10)
1738
+ // What `color-scheme` the native 「选末尾条数」 dropdown has to declare
1739
+ // so its popup is painted the way the app around it is. Measured when
1740
+ // the picker opens, because that is when the popup can next appear.
1741
+ const [scheme, setScheme] = React.useState('dark')
1742
+ const headRef = React.useRef(null)
1689
1743
  const [busy, setBusy] = React.useState(false)
1690
1744
  const [toast, setToast] = React.useState('')
1691
1745
  // Bumped only by the explicit 「重新读取」 button. It is separate from
@@ -1850,6 +1904,14 @@ window.__ModuleLoader__.load({
1850
1904
  setOverlaySuppressed(pickerOpen)
1851
1905
  }, [pickerOpen])
1852
1906
 
1907
+ // Tell the native dropdown which way to paint its popup. Runs after
1908
+ // the header row is in the document, which is the first moment the
1909
+ // surface under it can be measured.
1910
+ React.useEffect(() => {
1911
+ if (!pickerOpen) return
1912
+ setScheme(controlScheme(headRef.current))
1913
+ }, [pickerOpen])
1914
+
1853
1915
  // Read the session's messages when the picker opens, when the advanced
1854
1916
  // switch flips, when the Session changes, and when the user asks for a
1855
1917
  // re-read. Deliberately *not* on `version`: that is bumped by notify(),
@@ -1934,7 +1996,7 @@ window.__ModuleLoader__.load({
1934
1996
 
1935
1997
  const chosen = React.useMemo(() => {
1936
1998
  if (messages === null) return []
1937
- return messages.filter((row) => selected.has(row.seq))
1999
+ return messages.filter((row) => selected.has(row.id))
1938
2000
  }, [messages, selected])
1939
2001
 
1940
2002
  // The note travels with the quoted rows, so it is composed here rather
@@ -1962,10 +2024,10 @@ window.__ModuleLoader__.load({
1962
2024
  React.useEffect(() => {
1963
2025
  const node = listRef.current
1964
2026
  if (node === null) return
1965
- const anchorSeq = anchoredRef.current
1966
- if (anchorSeq !== null) {
2027
+ const anchorId = anchoredRef.current
2028
+ if (anchorId !== null) {
1967
2029
  anchoredRef.current = null
1968
- const anchor = node.querySelector(`[data-seq="${anchorSeq}"]`)
2030
+ const anchor = node.querySelector(`[data-id="${anchorId}"]`)
1969
2031
  if (anchor !== null) {
1970
2032
  node.scrollTop = anchor.offsetTop - node.offsetTop
1971
2033
  return
@@ -1974,11 +2036,15 @@ window.__ModuleLoader__.load({
1974
2036
  node.scrollTop = node.scrollHeight
1975
2037
  }, [messages, pickerOpen, pageSize])
1976
2038
 
1977
- const toggle = React.useCallback((seq) => {
2039
+ // Ticking is a plain set flip on the row's `id`. The row itself is the
2040
+ // click target (see the row markup), so there is exactly one handler
2041
+ // between the pointer and the state — no `<label>` forwarding a click
2042
+ // to a hidden `<input>` behind React's back.
2043
+ const toggle = React.useCallback((id) => {
1978
2044
  setSelected((current) => {
1979
2045
  const next = new Set(current)
1980
- if (next.has(seq)) next.delete(seq)
1981
- else next.add(seq)
2046
+ if (next.has(id)) next.delete(id)
2047
+ else next.add(id)
1982
2048
  return next
1983
2049
  })
1984
2050
  }, [])
@@ -2112,7 +2178,7 @@ window.__ModuleLoader__.load({
2112
2178
  // Paged from the newest rows backwards. The list opens scrolled to the
2113
2179
  // bottom, so the newest few are what a person reads and picks from;
2114
2180
  // older rows are pulled in a page at a time from the top. Selection is
2115
- // by `seq`, not by mounted row, so 全选 and 选末尾 still act on the whole
2181
+ // by row id, not by mounted row, so 全选 and 选末尾 still act on the whole
2116
2182
  // session however few rows are on screen.
2117
2183
  const total = messages === null ? 0 : messages.length
2118
2184
  const start = Math.max(0, total - pageSize)
@@ -2142,7 +2208,7 @@ window.__ModuleLoader__.load({
2142
2208
  : node.querySelector('.dswc-row')
2143
2209
  anchoredRef.current = first === null
2144
2210
  ? null
2145
- : first.getAttribute('data-seq')
2211
+ : first.getAttribute('data-id')
2146
2212
  setPageSize((size) => size + LIST_PAGE_SIZE)
2147
2213
  },
2148
2214
  }, format(t('action.loadEarlier'), {
@@ -2160,35 +2226,50 @@ window.__ModuleLoader__.load({
2160
2226
  ? null
2161
2227
  : h('div', { key: 'dropped', className: 'dswc-more' },
2162
2228
  format(t('picker.droppedEarlier'), { count: dropped })),
2163
- ...shown.map((row) => h('label', {
2164
- key: row.seq,
2165
- className: 'dswc-row',
2166
- 'data-role': row.role,
2167
- 'data-kind': row.kind ?? row.role,
2168
- 'data-seq': String(row.seq),
2169
- }, [
2170
- h('input', {
2171
- key: 'box',
2172
- type: 'checkbox',
2173
- checked: selected.has(row.seq),
2174
- onChange: () => toggle(row.seq),
2175
- }),
2176
- h('span', {
2177
- key: 'role',
2178
- className: 'dswc-role',
2179
- title: kindLabel(row, labels),
2229
+ ...shown.map((row) => {
2230
+ const ticked = selected.has(row.id)
2231
+ return h('div', {
2232
+ key: row.id,
2233
+ className: 'dswc-row',
2234
+ // The whole row is the control. It used to be a
2235
+ // `<label>` wrapping a native checkbox, so a click on
2236
+ // the text only reached the input by the browser
2237
+ // forwarding it, and the row's identity was the raw
2238
+ // event `seq` — which a sibling row from the same
2239
+ // event also carried. One element, one handler now,
2240
+ // and `row.id` is unique.
2241
+ role: 'checkbox',
2242
+ tabIndex: 0,
2243
+ 'aria-checked': ticked ? 'true' : 'false',
2244
+ 'data-role': row.role,
2245
+ 'data-kind': row.kind ?? row.role,
2246
+ 'data-id': row.id,
2247
+ 'data-seq': String(row.seq),
2248
+ onClick: () => toggle(row.id),
2249
+ onKeyDown: (event) => {
2250
+ if (event.key !== ' ' && event.key !== 'Enter') return
2251
+ event.preventDefault()
2252
+ toggle(row.id)
2253
+ },
2180
2254
  }, [
2181
- KindIcon(row.kind ?? row.role),
2182
- h('span', { key: 'label', className: 'dswc-roleLabel' }, kindLabel(row, labels)),
2183
- ]),
2184
- h('span', { key: 'text', className: 'dswc-text' }, row.text),
2185
- ])),
2255
+ h('span', { key: 'box', className: 'dswc-box', 'aria-hidden': 'true' }),
2256
+ h('span', {
2257
+ key: 'role',
2258
+ className: 'dswc-role',
2259
+ title: kindLabel(row, labels),
2260
+ }, [
2261
+ KindIcon(row.kind ?? row.role),
2262
+ h('span', { key: 'label', className: 'dswc-roleLabel' }, kindLabel(row, labels)),
2263
+ ]),
2264
+ h('span', { key: 'text', className: 'dswc-text' }, row.text),
2265
+ ])
2266
+ }),
2186
2267
  ])
2187
2268
 
2188
2269
  return h('div', { className: 'dswc-root' }, [
2189
2270
  toolbar,
2190
2271
  h('div', { key: 'picker', className: 'dswc-picker' }, [
2191
- h('div', { key: 'head', className: 'dswc-pickerHead' }, [
2272
+ h('div', { key: 'head', className: 'dswc-pickerHead', ref: headRef }, [
2192
2273
  h('span', { key: 'title', className: 'dswc-pickerTitle' }, t('picker.title')),
2193
2274
  h('span', { key: 'count', className: 'dswc-muted' },
2194
2275
  format(t('picker.selected'), { count: chosen.length })),
@@ -2197,7 +2278,7 @@ window.__ModuleLoader__.load({
2197
2278
  key: 'all',
2198
2279
  type: 'button',
2199
2280
  className: 'dswc-button',
2200
- onClick: () => setSelected(new Set((messages ?? []).map((row) => row.seq))),
2281
+ onClick: () => setSelected(new Set((messages ?? []).map((row) => row.id))),
2201
2282
  }, t('action.all')),
2202
2283
  h('button', {
2203
2284
  key: 'none',
@@ -2210,6 +2291,11 @@ window.__ModuleLoader__.load({
2210
2291
  h('select', {
2211
2292
  key: 'lastN',
2212
2293
  className: 'dswc-select',
2294
+ // Without this the popup is drawn with the browser's own
2295
+ // light defaults while the option text inherits the app's
2296
+ // ink, which is how the list came to look empty until a
2297
+ // row was hovered.
2298
+ style: { colorScheme: scheme },
2213
2299
  title: t('picker.lastCount'),
2214
2300
  'aria-label': t('picker.lastCount'),
2215
2301
  value: String(lastN),
@@ -2223,7 +2309,7 @@ window.__ModuleLoader__.load({
2223
2309
  onClick: () => {
2224
2310
  const rows = messages ?? []
2225
2311
  setSelected(new Set(
2226
- rows.slice(Math.max(0, rows.length - lastN)).map((row) => row.seq),
2312
+ rows.slice(Math.max(0, rows.length - lastN)).map((row) => row.id),
2227
2313
  ))
2228
2314
  },
2229
2315
  }, t('action.last')),
package/lib/index.js CHANGED
@@ -418,7 +418,9 @@ export function boundRows(rows) {
418
418
  *
419
419
  * @param events - raw events from `ctx.sessionQuery.readSession`.
420
420
  * @param options - `{ advanced }` to include the machinery rows.
421
- * @returns `{ seq, role, kind, text }` rows in log order, empty ones dropped.
421
+ * @returns `{ id, seq, role, kind, text }` rows in log order, empty ones
422
+ * dropped. `id` is unique per row; `seq` is the event it came from and is
423
+ * not unique (see the ordinal pass at the end).
422
424
  */
423
425
  export function extractMessages(events, options = {}) {
424
426
  if (!Array.isArray(events)) return []
@@ -555,6 +557,23 @@ export function extractMessages(events, options = {}) {
555
557
  }
556
558
  }
557
559
 
560
+ // One event can yield several rows — an assistant message carries its text
561
+ // *and* its reasoning *and* one row per tool call — so `seq` does not
562
+ // identify a row. The picker ticks rows by `id` and hands it to React as the
563
+ // child key; keying by `seq` made the rows that share one share a checkbox
564
+ // (ticking any of them ticked all of them) and collide as React keys, which
565
+ // is what made those rows feel like they would not take a click.
566
+ //
567
+ // The ordinal is per `seq` and derived from log order, so it is stable across
568
+ // re-reads of the same session, and a row dropped off the front by the size
569
+ // cap cannot shift the ids of the rows after it.
570
+ const ordinals = new Map()
571
+ for (const row of rows) {
572
+ const ordinal = ordinals.get(row.seq) ?? 0
573
+ ordinals.set(row.seq, ordinal + 1)
574
+ row.id = row.seq + ':' + ordinal
575
+ }
576
+
558
577
  return rows
559
578
  }
560
579
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-deepseek-webchat",
3
- "version": "0.4.10",
3
+ "version": "0.4.11",
4
4
  "description": "Embeds the official chat.deepseek.com web app in a DSH sidebar tab through the desktop shell's native browser guest, binds one DeepSeek conversation per DSH Session, and sends selected DSH context into the DeepSeek composer as a blockquote.",
5
5
  "keywords": [
6
6
  "dsh",
@@ -104,7 +104,7 @@ window.__ModuleLoader__.load({
104
104
  * plus laying out all of them blocks the main thread: 73 ms for 555, mostly
105
105
  * the forced layout. The list opens on the newest few, which is what a
106
106
  * person actually picks from, and older rows are loaded a page at a time
107
- * from the top. Selection is by `seq`, so the bulk actions still cover the
107
+ * from the top. Selection is by row id, so the bulk actions still cover the
108
108
  * whole session rather than only what is mounted.
109
109
  */
110
110
  const LIST_PAGE_SIZE = 10
@@ -598,9 +598,22 @@ window.__ModuleLoader__.load({
598
598
  '.dswc-muted{color:var(--dsw-alias-label-tertiary,#adb2b8);font-size:11px}',
599
599
  '.dswc-more{position:sticky;top:0;display:flex;align-items:center;gap:8px;padding:6px 8px;background:var(--dsw-alias-bg-layer-1,#fff);border-bottom:1px solid var(--dsw-alias-border-l4,rgba(128,128,128,.25))}',
600
600
  '.dswc-list{flex:1 1 auto;min-height:60px;overflow:auto;border:1px solid var(--dsw-alias-border-l4,rgba(128,128,128,.25));border-radius:var(--dsw-radius-md,12px)}',
601
- '.dswc-row{display:flex;gap:6px;padding:6px 8px;cursor:pointer;border-bottom:1px solid var(--dsw-alias-border-l4,rgba(128,128,128,.15))}',
601
+ '.dswc-row{display:flex;align-items:flex-start;gap:6px;padding:6px 8px;cursor:pointer;border-bottom:1px solid var(--dsw-alias-border-l4,rgba(128,128,128,.15));user-select:none;-webkit-user-select:none;outline:none}',
602
602
  '.dswc-row:last-child{border-bottom:0}',
603
603
  '.dswc-row:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.08))}',
604
+ '.dswc-row:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary,#4d6bfe);outline-offset:-2px}',
605
+ // The tick box. It is drawn rather than inherited: a native checkbox
606
+ // inside a label made one click travel through the label's
607
+ // forwarding rule, and its size/ink came from whatever the shell's
608
+ // global form styles happened to be.
609
+ '.dswc-box{flex:none;box-sizing:border-box;width:13px;height:13px;margin-top:2px;position:relative;border:1px solid var(--dsw-alias-border-l4,rgba(128,128,128,.55));border-radius:3px;background:transparent}',
610
+ '.dswc-row:hover .dswc-box{border-color:var(--dsw-alias-label-secondary,#cfd3d6)}',
611
+ '.dswc-row[aria-checked="true"] .dswc-box{border-color:var(--dsw-alias-state-business-primary,#4d6bfe);background:var(--dsw-alias-state-business-primary,#4d6bfe)}',
612
+ '.dswc-row[aria-checked="true"] .dswc-box::after{content:"";position:absolute;left:3.5px;top:0.5px;width:4px;height:8px;border:solid #fff;border-width:0 1.5px 1.5px 0;transform:rotate(45deg)}',
613
+ '.dswc-row[aria-checked="true"]{background:rgba(77,107,254,.08)}',
614
+ '.dswc-row[aria-checked="true"]{background:color-mix(in srgb,var(--dsw-alias-state-business-primary,#4d6bfe) 10%,transparent)}',
615
+ '.dswc-row[aria-checked="true"]:hover{background:rgba(77,107,254,.14)}',
616
+ '.dswc-row[aria-checked="true"]:hover{background:color-mix(in srgb,var(--dsw-alias-state-business-primary,#4d6bfe) 16%,transparent)}',
604
617
  // The row marker is an icon from the shell's own set plus a short
605
618
  // word, inside a fixed-width column so the text of every row starts
606
619
  // at the same place however long the label is.
@@ -1658,6 +1671,42 @@ window.__ModuleLoader__.load({
1658
1671
  return ChatBubbleGlyph(props)
1659
1672
  }
1660
1673
 
1674
+ /**
1675
+ * Which way the browser should paint a native control's own surfaces.
1676
+ *
1677
+ * The shell paints a dark app without declaring `color-scheme`, so the
1678
+ * popup of a native `<select>` is drawn light (browser default) while
1679
+ * its option text inherits the app's near-white ink: the list reads as
1680
+ * blank, and a row only becomes legible while the pointer is over it and
1681
+ * the hover highlight paints something behind the text. `color-scheme`
1682
+ * is exactly the hint that makes the popup and the ink agree, and the
1683
+ * surface the control actually sits on is the honest source for it —
1684
+ * no guessing at the shell's theme attribute.
1685
+ *
1686
+ * @param element - any node inside the pane.
1687
+ * @returns `'dark'` or `'light'`.
1688
+ */
1689
+ function controlScheme(element) {
1690
+ const osDark = typeof matchMedia === 'function'
1691
+ && matchMedia('(prefers-color-scheme: dark)').matches
1692
+ const fallback = osDark ? 'dark' : 'light'
1693
+ let node = element
1694
+ while (node !== null && node !== undefined && typeof node !== 'string') {
1695
+ const match = /rgba?\(([^)]+)\)/.exec(String(window.getComputedStyle(node).backgroundColor))
1696
+ if (match !== null) {
1697
+ const [r, g, b, a = 1] = match[1].split(',').map((part) => Number.parseFloat(part))
1698
+ if ([r, g, b, a].every((part) => Number.isFinite(part)) && a > 0.4) {
1699
+ // Perceived luminance. The exact weights do not matter; only
1700
+ // which side of half the surface falls on does.
1701
+ const luma = (0.2126 * r + 0.7152 * g + 0.0722 * b) / 255
1702
+ return luma > 0.5 ? 'light' : 'dark'
1703
+ }
1704
+ }
1705
+ node = node.parentElement ?? null
1706
+ }
1707
+ return fallback
1708
+ }
1709
+
1661
1710
  /**
1662
1711
  * The tab body: a toolbar, and either the picker or the measured guest area.
1663
1712
  * @param props - standard slot props plus the injected session id.
@@ -1686,6 +1735,11 @@ window.__ModuleLoader__.load({
1686
1735
  const [advanced, setAdvanced] = React.useState(false)
1687
1736
  const [preamble, setPreamble] = React.useState(true)
1688
1737
  const [lastN, setLastN] = React.useState(10)
1738
+ // What `color-scheme` the native 「选末尾条数」 dropdown has to declare
1739
+ // so its popup is painted the way the app around it is. Measured when
1740
+ // the picker opens, because that is when the popup can next appear.
1741
+ const [scheme, setScheme] = React.useState('dark')
1742
+ const headRef = React.useRef(null)
1689
1743
  const [busy, setBusy] = React.useState(false)
1690
1744
  const [toast, setToast] = React.useState('')
1691
1745
  // Bumped only by the explicit 「重新读取」 button. It is separate from
@@ -1850,6 +1904,14 @@ window.__ModuleLoader__.load({
1850
1904
  setOverlaySuppressed(pickerOpen)
1851
1905
  }, [pickerOpen])
1852
1906
 
1907
+ // Tell the native dropdown which way to paint its popup. Runs after
1908
+ // the header row is in the document, which is the first moment the
1909
+ // surface under it can be measured.
1910
+ React.useEffect(() => {
1911
+ if (!pickerOpen) return
1912
+ setScheme(controlScheme(headRef.current))
1913
+ }, [pickerOpen])
1914
+
1853
1915
  // Read the session's messages when the picker opens, when the advanced
1854
1916
  // switch flips, when the Session changes, and when the user asks for a
1855
1917
  // re-read. Deliberately *not* on `version`: that is bumped by notify(),
@@ -1934,7 +1996,7 @@ window.__ModuleLoader__.load({
1934
1996
 
1935
1997
  const chosen = React.useMemo(() => {
1936
1998
  if (messages === null) return []
1937
- return messages.filter((row) => selected.has(row.seq))
1999
+ return messages.filter((row) => selected.has(row.id))
1938
2000
  }, [messages, selected])
1939
2001
 
1940
2002
  // The note travels with the quoted rows, so it is composed here rather
@@ -1962,10 +2024,10 @@ window.__ModuleLoader__.load({
1962
2024
  React.useEffect(() => {
1963
2025
  const node = listRef.current
1964
2026
  if (node === null) return
1965
- const anchorSeq = anchoredRef.current
1966
- if (anchorSeq !== null) {
2027
+ const anchorId = anchoredRef.current
2028
+ if (anchorId !== null) {
1967
2029
  anchoredRef.current = null
1968
- const anchor = node.querySelector(`[data-seq="${anchorSeq}"]`)
2030
+ const anchor = node.querySelector(`[data-id="${anchorId}"]`)
1969
2031
  if (anchor !== null) {
1970
2032
  node.scrollTop = anchor.offsetTop - node.offsetTop
1971
2033
  return
@@ -1974,11 +2036,15 @@ window.__ModuleLoader__.load({
1974
2036
  node.scrollTop = node.scrollHeight
1975
2037
  }, [messages, pickerOpen, pageSize])
1976
2038
 
1977
- const toggle = React.useCallback((seq) => {
2039
+ // Ticking is a plain set flip on the row's `id`. The row itself is the
2040
+ // click target (see the row markup), so there is exactly one handler
2041
+ // between the pointer and the state — no `<label>` forwarding a click
2042
+ // to a hidden `<input>` behind React's back.
2043
+ const toggle = React.useCallback((id) => {
1978
2044
  setSelected((current) => {
1979
2045
  const next = new Set(current)
1980
- if (next.has(seq)) next.delete(seq)
1981
- else next.add(seq)
2046
+ if (next.has(id)) next.delete(id)
2047
+ else next.add(id)
1982
2048
  return next
1983
2049
  })
1984
2050
  }, [])
@@ -2112,7 +2178,7 @@ window.__ModuleLoader__.load({
2112
2178
  // Paged from the newest rows backwards. The list opens scrolled to the
2113
2179
  // bottom, so the newest few are what a person reads and picks from;
2114
2180
  // older rows are pulled in a page at a time from the top. Selection is
2115
- // by `seq`, not by mounted row, so 全选 and 选末尾 still act on the whole
2181
+ // by row id, not by mounted row, so 全选 and 选末尾 still act on the whole
2116
2182
  // session however few rows are on screen.
2117
2183
  const total = messages === null ? 0 : messages.length
2118
2184
  const start = Math.max(0, total - pageSize)
@@ -2142,7 +2208,7 @@ window.__ModuleLoader__.load({
2142
2208
  : node.querySelector('.dswc-row')
2143
2209
  anchoredRef.current = first === null
2144
2210
  ? null
2145
- : first.getAttribute('data-seq')
2211
+ : first.getAttribute('data-id')
2146
2212
  setPageSize((size) => size + LIST_PAGE_SIZE)
2147
2213
  },
2148
2214
  }, format(t('action.loadEarlier'), {
@@ -2160,35 +2226,50 @@ window.__ModuleLoader__.load({
2160
2226
  ? null
2161
2227
  : h('div', { key: 'dropped', className: 'dswc-more' },
2162
2228
  format(t('picker.droppedEarlier'), { count: dropped })),
2163
- ...shown.map((row) => h('label', {
2164
- key: row.seq,
2165
- className: 'dswc-row',
2166
- 'data-role': row.role,
2167
- 'data-kind': row.kind ?? row.role,
2168
- 'data-seq': String(row.seq),
2169
- }, [
2170
- h('input', {
2171
- key: 'box',
2172
- type: 'checkbox',
2173
- checked: selected.has(row.seq),
2174
- onChange: () => toggle(row.seq),
2175
- }),
2176
- h('span', {
2177
- key: 'role',
2178
- className: 'dswc-role',
2179
- title: kindLabel(row, labels),
2229
+ ...shown.map((row) => {
2230
+ const ticked = selected.has(row.id)
2231
+ return h('div', {
2232
+ key: row.id,
2233
+ className: 'dswc-row',
2234
+ // The whole row is the control. It used to be a
2235
+ // `<label>` wrapping a native checkbox, so a click on
2236
+ // the text only reached the input by the browser
2237
+ // forwarding it, and the row's identity was the raw
2238
+ // event `seq` — which a sibling row from the same
2239
+ // event also carried. One element, one handler now,
2240
+ // and `row.id` is unique.
2241
+ role: 'checkbox',
2242
+ tabIndex: 0,
2243
+ 'aria-checked': ticked ? 'true' : 'false',
2244
+ 'data-role': row.role,
2245
+ 'data-kind': row.kind ?? row.role,
2246
+ 'data-id': row.id,
2247
+ 'data-seq': String(row.seq),
2248
+ onClick: () => toggle(row.id),
2249
+ onKeyDown: (event) => {
2250
+ if (event.key !== ' ' && event.key !== 'Enter') return
2251
+ event.preventDefault()
2252
+ toggle(row.id)
2253
+ },
2180
2254
  }, [
2181
- KindIcon(row.kind ?? row.role),
2182
- h('span', { key: 'label', className: 'dswc-roleLabel' }, kindLabel(row, labels)),
2183
- ]),
2184
- h('span', { key: 'text', className: 'dswc-text' }, row.text),
2185
- ])),
2255
+ h('span', { key: 'box', className: 'dswc-box', 'aria-hidden': 'true' }),
2256
+ h('span', {
2257
+ key: 'role',
2258
+ className: 'dswc-role',
2259
+ title: kindLabel(row, labels),
2260
+ }, [
2261
+ KindIcon(row.kind ?? row.role),
2262
+ h('span', { key: 'label', className: 'dswc-roleLabel' }, kindLabel(row, labels)),
2263
+ ]),
2264
+ h('span', { key: 'text', className: 'dswc-text' }, row.text),
2265
+ ])
2266
+ }),
2186
2267
  ])
2187
2268
 
2188
2269
  return h('div', { className: 'dswc-root' }, [
2189
2270
  toolbar,
2190
2271
  h('div', { key: 'picker', className: 'dswc-picker' }, [
2191
- h('div', { key: 'head', className: 'dswc-pickerHead' }, [
2272
+ h('div', { key: 'head', className: 'dswc-pickerHead', ref: headRef }, [
2192
2273
  h('span', { key: 'title', className: 'dswc-pickerTitle' }, t('picker.title')),
2193
2274
  h('span', { key: 'count', className: 'dswc-muted' },
2194
2275
  format(t('picker.selected'), { count: chosen.length })),
@@ -2197,7 +2278,7 @@ window.__ModuleLoader__.load({
2197
2278
  key: 'all',
2198
2279
  type: 'button',
2199
2280
  className: 'dswc-button',
2200
- onClick: () => setSelected(new Set((messages ?? []).map((row) => row.seq))),
2281
+ onClick: () => setSelected(new Set((messages ?? []).map((row) => row.id))),
2201
2282
  }, t('action.all')),
2202
2283
  h('button', {
2203
2284
  key: 'none',
@@ -2210,6 +2291,11 @@ window.__ModuleLoader__.load({
2210
2291
  h('select', {
2211
2292
  key: 'lastN',
2212
2293
  className: 'dswc-select',
2294
+ // Without this the popup is drawn with the browser's own
2295
+ // light defaults while the option text inherits the app's
2296
+ // ink, which is how the list came to look empty until a
2297
+ // row was hovered.
2298
+ style: { colorScheme: scheme },
2213
2299
  title: t('picker.lastCount'),
2214
2300
  'aria-label': t('picker.lastCount'),
2215
2301
  value: String(lastN),
@@ -2223,7 +2309,7 @@ window.__ModuleLoader__.load({
2223
2309
  onClick: () => {
2224
2310
  const rows = messages ?? []
2225
2311
  setSelected(new Set(
2226
- rows.slice(Math.max(0, rows.length - lastN)).map((row) => row.seq),
2312
+ rows.slice(Math.max(0, rows.length - lastN)).map((row) => row.id),
2227
2313
  ))
2228
2314
  },
2229
2315
  }, t('action.last')),
package/src/index.js CHANGED
@@ -418,7 +418,9 @@ export function boundRows(rows) {
418
418
  *
419
419
  * @param events - raw events from `ctx.sessionQuery.readSession`.
420
420
  * @param options - `{ advanced }` to include the machinery rows.
421
- * @returns `{ seq, role, kind, text }` rows in log order, empty ones dropped.
421
+ * @returns `{ id, seq, role, kind, text }` rows in log order, empty ones
422
+ * dropped. `id` is unique per row; `seq` is the event it came from and is
423
+ * not unique (see the ordinal pass at the end).
422
424
  */
423
425
  export function extractMessages(events, options = {}) {
424
426
  if (!Array.isArray(events)) return []
@@ -555,6 +557,23 @@ export function extractMessages(events, options = {}) {
555
557
  }
556
558
  }
557
559
 
560
+ // One event can yield several rows — an assistant message carries its text
561
+ // *and* its reasoning *and* one row per tool call — so `seq` does not
562
+ // identify a row. The picker ticks rows by `id` and hands it to React as the
563
+ // child key; keying by `seq` made the rows that share one share a checkbox
564
+ // (ticking any of them ticked all of them) and collide as React keys, which
565
+ // is what made those rows feel like they would not take a click.
566
+ //
567
+ // The ordinal is per `seq` and derived from log order, so it is stable across
568
+ // re-reads of the same session, and a row dropped off the front by the size
569
+ // cap cannot shift the ids of the rows after it.
570
+ const ordinals = new Map()
571
+ for (const row of rows) {
572
+ const ordinal = ordinals.get(row.seq) ?? 0
573
+ ordinals.set(row.seq, ordinal + 1)
574
+ row.id = row.seq + ':' + ordinal
575
+ }
576
+
558
577
  return rows
559
578
  }
560
579