dsh-content-search-ad 0.28.0 → 0.29.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 +64 -31
  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.28.0'
22
+ const PLUGIN_VERSION = '0.29.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. */
@@ -1125,43 +1125,76 @@ window.__ModuleLoader__.load({
1125
1125
  return [anchor, tail, whole.slice(0, 60), middle, whole.slice(0, 30), anchor.slice(0, 24)]
1126
1126
  }
1127
1127
 
1128
+ /**
1129
+ /** The user message bubbles the transcript has rendered, in document order. */
1130
+ function userBubbles() {
1131
+ if (typeof document === 'undefined') return []
1132
+ return Array.from(document.querySelectorAll('[data-message-bubble]'))
1133
+ }
1134
+
1135
+ /**
1136
+ * The bubble for one question, by its ordinal in the conversation.
1137
+ *
1138
+ * The transcript renders a window ending at the newest message, so bubble `i`
1139
+ * is question `total - bubbles + i`. Returns `undefined` when that message is
1140
+ * not rendered yet, which is the signal to page history first.
1141
+ */
1142
+ function bubbleForQuestion(index, total) {
1143
+ const bubbles = userBubbles()
1144
+ const offset = Math.max(0, total - bubbles.length)
1145
+ const target = index - offset
1146
+ if (target < 0 || target >= bubbles.length) return undefined
1147
+ return bubbles[target]
1148
+ }
1149
+
1150
+ /** Mark one whole node and bring it into view. */
1151
+ function paintNode(node) {
1152
+ if (node === undefined || node === null) return false
1153
+ const ranges = rangesForNode(node)
1154
+ if (ranges.length === 0) return false
1155
+ CSS.highlights.set(ACTIVE_NAME, new Highlight(...ranges))
1156
+ revealElement(node)
1157
+ return true
1158
+ }
1159
+
1128
1160
  /**
1129
1161
  * Center one question in the transcript, paging history to it when needed.
1130
1162
  *
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.
1163
+ * Order matters: two prompts can read almost identically (`……代码…你觉得呢`),
1164
+ * so the ordinal among the conversation's questions decides first, and text
1165
+ * anchors are only the fallback for when the bubble list disagrees.
1166
+ * Resolves to whether the message was found.
1134
1167
  */
1135
- async function revealText(sessionId, anchor, seq, text) {
1136
- if (typeof anchor !== 'string' || anchor.length < 4) return false
1168
+ async function revealText(sessionId, anchor, seq, text, index, total) {
1137
1169
  ensureHighlightStyle()
1138
1170
  if (!highlightSupported()) return false
1171
+ const ordinal = typeof index === 'number' && Number.isFinite(index)
1172
+ && typeof total === 'number' && Number.isFinite(total)
1139
1173
  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)
1150
- if (found !== undefined) {
1151
- paint(found)
1152
- return true
1153
- }
1154
- let paged = false
1155
- try {
1156
- paged = await pageToHit(sessionId, seq)
1157
- } catch {
1158
- paged = false
1174
+
1175
+ for (let round = 0; round < 2; round += 1) {
1176
+ if (ordinal) {
1177
+ const node = bubbleForQuestion(index, total)
1178
+ if (node !== undefined && paintNode(node)) return true
1179
+ }
1180
+ const found = findAnchorAny(indexTranscript(true), needles)
1181
+ if (found !== undefined) {
1182
+ const host = found.element !== null && typeof found.element.closest === 'function'
1183
+ ? found.element.closest('[data-message-bubble]') || found.element.closest('[data-chat-node-key]')
1184
+ : null
1185
+ if (paintNode(host !== null ? host : found.element)) return true
1186
+ }
1187
+ if (round === 0) {
1188
+ let paged = false
1189
+ try {
1190
+ paged = await pageToHit(sessionId, seq)
1191
+ } catch {
1192
+ paged = false
1193
+ }
1194
+ if (!paged) break
1195
+ }
1159
1196
  }
1160
- if (!paged) return false
1161
- const retry = findAnchorAny(indexTranscript(true), needles)
1162
- if (retry === undefined) return false
1163
- paint(retry)
1164
- return true
1197
+ return false
1165
1198
  }
1166
1199
  //#region component
1167
1200
  /**
@@ -1758,7 +1791,7 @@ window.__ModuleLoader__.load({
1758
1791
  title: question.text,
1759
1792
  onClick: () => {
1760
1793
  setLocateNote('')
1761
- revealText(focusSessionId, question.anchor, question.seq, question.text)
1794
+ revealText(focusSessionId, question.anchor, question.seq, question.text, index, questions.length)
1762
1795
  .then((ok) => {
1763
1796
  if (!ok) setLocateNote(t('detail.missing'))
1764
1797
  })
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.28.0'
67
+ const VERSION = '0.29.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.28.0",
3
+ "version": "0.29.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",