dsh-content-search-ad 0.27.2 → 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.
- package/client.js +98 -24
- package/index.js +1 -1
- 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.
|
|
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. */
|
|
@@ -815,6 +815,7 @@ window.__ModuleLoader__.load({
|
|
|
815
815
|
.dcs-results{flex:1 1 auto;min-height:0;overflow-y:auto;overscroll-behavior:contain;padding:6px 6px 10px}
|
|
816
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)}
|
|
817
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)}
|
|
818
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}
|
|
819
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}
|
|
820
821
|
.dcs-question:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}
|
|
@@ -1104,33 +1105,97 @@ window.__ModuleLoader__.load({
|
|
|
1104
1105
|
* message is older than the loaded window.
|
|
1105
1106
|
* @returns whether it was found immediately.
|
|
1106
1107
|
*/
|
|
1107
|
-
|
|
1108
|
-
|
|
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
|
+
/** 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
|
+
|
|
1160
|
+
/**
|
|
1161
|
+
* Center one question in the transcript, paging history to it when needed.
|
|
1162
|
+
*
|
|
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.
|
|
1167
|
+
*/
|
|
1168
|
+
async function revealText(sessionId, anchor, seq, text, index, total) {
|
|
1109
1169
|
ensureHighlightStyle()
|
|
1110
1170
|
if (!highlightSupported()) return false
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1171
|
+
const ordinal = typeof index === 'number' && Number.isFinite(index)
|
|
1172
|
+
&& typeof total === 'number' && Number.isFinite(total)
|
|
1173
|
+
const needles = anchorCandidates(anchor, text)
|
|
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
|
+
}
|
|
1124
1196
|
}
|
|
1125
|
-
pageToHit(sessionId, seq).then((paged) => {
|
|
1126
|
-
if (!paged) return
|
|
1127
|
-
const retry = findAnchor(indexTranscript(true), anchor)
|
|
1128
|
-
if (retry === undefined) return
|
|
1129
|
-
paint(retry)
|
|
1130
|
-
}).catch(() => {})
|
|
1131
1197
|
return false
|
|
1132
1198
|
}
|
|
1133
|
-
|
|
1134
1199
|
//#region component
|
|
1135
1200
|
/**
|
|
1136
1201
|
* Everything the panel needs to survive a tab remount: the sidebar is
|
|
@@ -1206,6 +1271,7 @@ window.__ModuleLoader__.load({
|
|
|
1206
1271
|
setScopeState(value)
|
|
1207
1272
|
}, [])
|
|
1208
1273
|
const [fontPx, setFontPx] = React.useState(readFont)
|
|
1274
|
+
const [locateNote, setLocateNote] = React.useState('')
|
|
1209
1275
|
const [recent, setRecent] = React.useState(readRecent)
|
|
1210
1276
|
const [questions, setQuestions] = React.useState([])
|
|
1211
1277
|
const [questionCount, setQuestionCount] = React.useState(0)
|
|
@@ -1711,6 +1777,7 @@ window.__ModuleLoader__.load({
|
|
|
1711
1777
|
questions.length > 0
|
|
1712
1778
|
? h('div', { className: 'dcs-chat' },
|
|
1713
1779
|
h('p', { className: 'dcs-section dcs-chat-head' }, t('questions.title', { n: questionCount })),
|
|
1780
|
+
locateNote.length > 0 ? h('p', { key: 'note', className: 'dcs-chat-note' }, locateNote) : null,
|
|
1714
1781
|
h('div', { className: 'dcs-chat-list', ref: chatListRef, onScroll: (event) => {
|
|
1715
1782
|
const node = event.currentTarget
|
|
1716
1783
|
chatStickRef.current = node.scrollHeight - node.scrollTop - node.clientHeight < 48
|
|
@@ -1722,7 +1789,14 @@ window.__ModuleLoader__.load({
|
|
|
1722
1789
|
className: 'dcs-question',
|
|
1723
1790
|
'data-hit': hit ? 'true' : 'false',
|
|
1724
1791
|
title: question.text,
|
|
1725
|
-
onClick: () =>
|
|
1792
|
+
onClick: () => {
|
|
1793
|
+
setLocateNote('')
|
|
1794
|
+
revealText(focusSessionId, question.anchor, question.seq, question.text, index, questions.length)
|
|
1795
|
+
.then((ok) => {
|
|
1796
|
+
if (!ok) setLocateNote(t('detail.missing'))
|
|
1797
|
+
})
|
|
1798
|
+
.catch(() => setLocateNote(t('detail.missing')))
|
|
1799
|
+
},
|
|
1726
1800
|
}, hit ? highlight(question.text, query, 'q' + index) : question.text)
|
|
1727
1801
|
})))
|
|
1728
1802
|
: null,
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-content-search-ad",
|
|
3
|
-
"version": "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",
|