dsh-content-search-ad 0.27.1 → 0.28.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.
Files changed (3) hide show
  1. package/client.js +81 -15
  2. package/index.js +1 -1
  3. package/package.json +1 -1
package/client.js CHANGED
@@ -19,7 +19,7 @@ window.__ModuleLoader__.load({
19
19
  /** Locale namespace owned by this plugin. */
20
20
  const NS = 'contentSearch'
21
21
  /** Plugin version, shown in the panel so a running build can be identified. */
22
- const PLUGIN_VERSION = '0.27.1'
22
+ const PLUGIN_VERSION = '0.28.0'
23
23
  /** Tab-type identity; the body slot registers under the same key. */
24
24
  const TAB_ID = 'dsh-content-search-ad/panel'
25
25
  /** Page kind opened by the guide card and the strip's add control. */
@@ -580,6 +580,24 @@ window.__ModuleLoader__.load({
580
580
  }
581
581
  }
582
582
 
583
+ /** Every text range inside one chat node, so a whole message can be marked. */
584
+ function rangesForNode(node) {
585
+ if (node === undefined || node === null || typeof node.querySelectorAll !== 'function') return []
586
+ const ranges = []
587
+ const walker = document.createTreeWalker(node, NodeFilter.SHOW_TEXT, null)
588
+ let text = walker.nextNode()
589
+ while (text !== null && ranges.length < HIGHLIGHT_MAX_RANGES) {
590
+ const value = text.nodeValue
591
+ if (typeof value === 'string' && value.trim().length > 0) {
592
+ const range = document.createRange()
593
+ range.selectNodeContents(text)
594
+ ranges.push(range)
595
+ }
596
+ text = walker.nextNode()
597
+ }
598
+ return ranges
599
+ }
600
+
583
601
  /**
584
602
  * Find the occurrence an anchor window describes.
585
603
  *
@@ -797,6 +815,7 @@ window.__ModuleLoader__.load({
797
815
  .dcs-results{flex:1 1 auto;min-height:0;overflow-y:auto;overscroll-behavior:contain;padding:6px 6px 10px}
798
816
  .dcs-chat{flex:0 0 auto;display:flex;flex-direction:column;max-height:42%;border-top:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-1)}
799
817
  .dcs-chat-head{flex:0 0 auto;margin:9px 10px 5px;font-size:.9em;line-height:1.4}
818
+ .dcs-chat-note{margin:0 10px 5px;font-size:.85em;line-height:1.4;color:var(--dsw-alias-label-tertiary)}
800
819
  .dcs-chat-list{flex:1 1 auto;min-height:0;overflow-y:auto;overscroll-behavior:contain;padding:2px 8px 8px;display:flex;flex-direction:column;gap:6px}
801
820
  .dcs-question{flex:0 0 auto;min-height:2.4em;width:100%;box-sizing:border-box;padding:.55em .7em;border:1px solid var(--dsw-alias-border-l1);border-radius:var(--dsw-radius-sm);background:var(--dsw-alias-bg-layer-2,transparent);color:var(--dsw-alias-label-secondary);font:inherit;font-size:.95em;line-height:1.55;text-align:left;cursor:pointer;white-space:normal;overflow-wrap:anywhere}
802
821
  .dcs-question:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}
@@ -1086,26 +1105,64 @@ window.__ModuleLoader__.load({
1086
1105
  * message is older than the loaded window.
1087
1106
  * @returns whether it was found immediately.
1088
1107
  */
1089
- function revealText(sessionId, anchor, seq) {
1108
+ /** Try several anchor windows, best first, and return the first transcript hit. */
1109
+ function findAnchorAny(blocks, needles) {
1110
+ for (const needle of needles) {
1111
+ if (typeof needle !== 'string') continue
1112
+ const trimmed = needle.trim()
1113
+ if (trimmed.length < 6) continue
1114
+ const hit = findAnchor(blocks, trimmed)
1115
+ if (hit !== undefined) return hit
1116
+ }
1117
+ return undefined
1118
+ }
1119
+
1120
+ /** Anchor windows worth trying for one question message. */
1121
+ function anchorCandidates(anchor, text) {
1122
+ const whole = typeof text === 'string' ? text : ''
1123
+ const tail = whole.length > 20 ? whole.slice(-80) : ''
1124
+ const middle = whole.length > 80 ? whole.slice(20, 100) : ''
1125
+ return [anchor, tail, whole.slice(0, 60), middle, whole.slice(0, 30), anchor.slice(0, 24)]
1126
+ }
1127
+
1128
+ /**
1129
+ * Center one question in the transcript, paging history to it when needed.
1130
+ *
1131
+ * A long prompt can start with pasted code, and the code's rendered text need
1132
+ * not equal the source, so the exact anchor is only the first candidate: the
1133
+ * tail and inner windows are tried next. Resolves to whether it was found.
1134
+ */
1135
+ async function revealText(sessionId, anchor, seq, text) {
1090
1136
  if (typeof anchor !== 'string' || anchor.length < 4) return false
1091
1137
  ensureHighlightStyle()
1092
1138
  if (!highlightSupported()) return false
1093
- const found = findAnchor(indexTranscript(true), anchor)
1139
+ const needles = anchorCandidates(anchor, text)
1140
+ /** Mark the whole chat node the anchor landed in, not just the window. */
1141
+ const paint = (hit) => {
1142
+ const host = hit.element !== null && typeof hit.element.closest === 'function'
1143
+ ? hit.element.closest('[data-chat-node-key]')
1144
+ : null
1145
+ const ranges = host !== null ? rangesForNode(host) : []
1146
+ CSS.highlights.set(ACTIVE_NAME, ranges.length > 0 ? new Highlight(...ranges) : new Highlight(hit.range))
1147
+ revealElement(hit.element)
1148
+ }
1149
+ const found = findAnchorAny(indexTranscript(true), needles)
1094
1150
  if (found !== undefined) {
1095
- CSS.highlights.set(ACTIVE_NAME, new Highlight(found.range))
1096
- revealElement(found.element)
1151
+ paint(found)
1097
1152
  return true
1098
1153
  }
1099
- pageToHit(sessionId, seq).then((paged) => {
1100
- if (!paged) return
1101
- const retry = findAnchor(indexTranscript(true), anchor)
1102
- if (retry === undefined) return
1103
- CSS.highlights.set(ACTIVE_NAME, new Highlight(retry.range))
1104
- revealElement(retry.element)
1105
- }).catch(() => {})
1106
- return false
1154
+ let paged = false
1155
+ try {
1156
+ paged = await pageToHit(sessionId, seq)
1157
+ } catch {
1158
+ paged = false
1159
+ }
1160
+ if (!paged) return false
1161
+ const retry = findAnchorAny(indexTranscript(true), needles)
1162
+ if (retry === undefined) return false
1163
+ paint(retry)
1164
+ return true
1107
1165
  }
1108
-
1109
1166
  //#region component
1110
1167
  /**
1111
1168
  * Everything the panel needs to survive a tab remount: the sidebar is
@@ -1181,6 +1238,7 @@ window.__ModuleLoader__.load({
1181
1238
  setScopeState(value)
1182
1239
  }, [])
1183
1240
  const [fontPx, setFontPx] = React.useState(readFont)
1241
+ const [locateNote, setLocateNote] = React.useState('')
1184
1242
  const [recent, setRecent] = React.useState(readRecent)
1185
1243
  const [questions, setQuestions] = React.useState([])
1186
1244
  const [questionCount, setQuestionCount] = React.useState(0)
@@ -1686,6 +1744,7 @@ window.__ModuleLoader__.load({
1686
1744
  questions.length > 0
1687
1745
  ? h('div', { className: 'dcs-chat' },
1688
1746
  h('p', { className: 'dcs-section dcs-chat-head' }, t('questions.title', { n: questionCount })),
1747
+ locateNote.length > 0 ? h('p', { key: 'note', className: 'dcs-chat-note' }, locateNote) : null,
1689
1748
  h('div', { className: 'dcs-chat-list', ref: chatListRef, onScroll: (event) => {
1690
1749
  const node = event.currentTarget
1691
1750
  chatStickRef.current = node.scrollHeight - node.scrollTop - node.clientHeight < 48
@@ -1697,7 +1756,14 @@ window.__ModuleLoader__.load({
1697
1756
  className: 'dcs-question',
1698
1757
  'data-hit': hit ? 'true' : 'false',
1699
1758
  title: question.text,
1700
- onClick: () => revealText(focusSessionId, question.anchor, question.seq),
1759
+ onClick: () => {
1760
+ setLocateNote('')
1761
+ revealText(focusSessionId, question.anchor, question.seq, question.text)
1762
+ .then((ok) => {
1763
+ if (!ok) setLocateNote(t('detail.missing'))
1764
+ })
1765
+ .catch(() => setLocateNote(t('detail.missing')))
1766
+ },
1701
1767
  }, hit ? highlight(question.text, query, 'q' + index) : question.text)
1702
1768
  })))
1703
1769
  : null,
package/index.js CHANGED
@@ -64,7 +64,7 @@ const FUZZY_MAX_CHARS = 12
64
64
  /** Shortest query, in code points, still worth a fuzzy pass. */
65
65
  const FUZZY_MIN_CHARS = 4
66
66
 
67
- const VERSION = '0.27.1'
67
+ const VERSION = '0.28.0'
68
68
 
69
69
  //#region http helpers
70
70
  function writeJson(res, status, value) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-content-search-ad",
3
- "version": "0.27.1",
3
+ "version": "0.28.0",
4
4
  "description": "DeepSeek Harness (DSH) plugin: full-text search over every conversation's prose from a right sidebar tab, with a jump-to-match detail view.",
5
5
  "license": "MIT",
6
6
  "author": "zmq6931",