dsh-content-search-ad 0.25.0 → 0.26.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 +17 -3
- package/index.js +74 -13
- 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.26.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. */
|
|
@@ -1161,6 +1161,8 @@ window.__ModuleLoader__.load({
|
|
|
1161
1161
|
? memory.anchorSessionId
|
|
1162
1162
|
: focusSessionId
|
|
1163
1163
|
const inputRef = React.useRef(null)
|
|
1164
|
+
const chatListRef = React.useRef(null)
|
|
1165
|
+
const chatStickRef = React.useRef(true)
|
|
1164
1166
|
const [query, setQuery] = React.useState(memory.query)
|
|
1165
1167
|
const [phase, setPhase] = React.useState(memory.query.trim().length > 0 ? 'loading' : 'idle')
|
|
1166
1168
|
const [rows, setRows] = React.useState(memory.rows)
|
|
@@ -1245,10 +1247,19 @@ window.__ModuleLoader__.load({
|
|
|
1245
1247
|
setQuestions((current) => (current.length === outcome.questions.length ? current : outcome.questions))
|
|
1246
1248
|
setQuestionCount(outcome.count)
|
|
1247
1249
|
}).catch(() => {})
|
|
1248
|
-
},
|
|
1250
|
+
}, 20000)
|
|
1249
1251
|
return () => clearInterval(timer)
|
|
1250
1252
|
}, [focusSessionId])
|
|
1251
1253
|
|
|
1254
|
+
// The list is a log: keep the newest question in view, unless the user has
|
|
1255
|
+
// scrolled up on purpose to read older ones.
|
|
1256
|
+
React.useEffect(() => {
|
|
1257
|
+
const node = chatListRef.current
|
|
1258
|
+
if (node === null) return
|
|
1259
|
+
if (!chatStickRef.current) return
|
|
1260
|
+
node.scrollTop = node.scrollHeight
|
|
1261
|
+
}, [questions])
|
|
1262
|
+
|
|
1252
1263
|
// The zoom buttons move this; the choice is remembered per browser.
|
|
1253
1264
|
const stepFont = React.useCallback((delta) => {
|
|
1254
1265
|
setFontPx((value) => {
|
|
@@ -1633,7 +1644,10 @@ window.__ModuleLoader__.load({
|
|
|
1633
1644
|
questions.length > 0
|
|
1634
1645
|
? h('div', { className: 'dcs-chat' },
|
|
1635
1646
|
h('p', { className: 'dcs-section dcs-chat-head' }, t('questions.title', { n: questionCount })),
|
|
1636
|
-
h('div', { className: 'dcs-chat-list'
|
|
1647
|
+
h('div', { className: 'dcs-chat-list', ref: chatListRef, onScroll: (event) => {
|
|
1648
|
+
const node = event.currentTarget
|
|
1649
|
+
chatStickRef.current = node.scrollHeight - node.scrollTop - node.clientHeight < 48
|
|
1650
|
+
} }, questions.map((question, index) => {
|
|
1637
1651
|
const hit = trimmed.length > 0 && matchesQuery(question.text, query)
|
|
1638
1652
|
return h('button', {
|
|
1639
1653
|
key: String(question.seq) + ':' + index,
|
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.
|
|
67
|
+
const VERSION = '0.26.0'
|
|
68
68
|
|
|
69
69
|
//#region http helpers
|
|
70
70
|
function writeJson(res, status, value) {
|
|
@@ -571,23 +571,21 @@ async function scanCorpus(ctx, parsed, focusId, scope) {
|
|
|
571
571
|
|
|
572
572
|
//#region questions
|
|
573
573
|
/** How many user messages the panel lists for one conversation. */
|
|
574
|
-
const QUESTIONS_MAX =
|
|
574
|
+
const QUESTIONS_MAX = 500
|
|
575
575
|
/** Longest question text sent for display. */
|
|
576
576
|
const QUESTION_TEXT_CHARS = 220
|
|
577
577
|
/** Longest anchor sent for locating the question in the transcript. */
|
|
578
578
|
const QUESTION_ANCHOR_CHARS = 80
|
|
579
|
+
/** How long a complete question list is served before the log is re-read. */
|
|
580
|
+
const QUESTIONS_CACHE_MS = 600000
|
|
581
|
+
/** Bound on cached conversations. */
|
|
582
|
+
const QUESTIONS_CACHE_MAX = 8
|
|
579
583
|
|
|
580
|
-
/**
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
* @returns `{ questions, count }` for the panel.
|
|
586
|
-
*/
|
|
587
|
-
async function questionsFor(ctx, sessionId) {
|
|
588
|
-
const query = ctx.sessionQuery
|
|
589
|
-
const surface = await query.readSurface(sessionId)
|
|
590
|
-
const events = surface !== null && surface !== undefined && Array.isArray(surface.events) ? surface.events : []
|
|
584
|
+
/** Extracted question lists per conversation, so the poll stays cheap. */
|
|
585
|
+
const questionCache = new Map()
|
|
586
|
+
|
|
587
|
+
/** Pull the human prompts out of a list of session events. */
|
|
588
|
+
function extractQuestions(events) {
|
|
591
589
|
const questions = []
|
|
592
590
|
for (const event of events) {
|
|
593
591
|
if (event === null || typeof event !== 'object' || event.type !== 'user/message') continue
|
|
@@ -616,10 +614,73 @@ async function questionsFor(ctx, sessionId) {
|
|
|
616
614
|
anchor: plain.slice(0, QUESTION_ANCHOR_CHARS),
|
|
617
615
|
})
|
|
618
616
|
}
|
|
617
|
+
return questions
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
/** Merge new questions into a cached list, keyed by event seq. */
|
|
621
|
+
function mergeQuestions(current, extra) {
|
|
622
|
+
if (extra.length === 0) return current
|
|
623
|
+
const bySeq = new Map()
|
|
624
|
+
for (const question of current) bySeq.set(question.seq, question)
|
|
625
|
+
let added = false
|
|
626
|
+
for (const question of extra) {
|
|
627
|
+
if (bySeq.has(question.seq)) continue
|
|
628
|
+
bySeq.set(question.seq, question)
|
|
629
|
+
added = true
|
|
630
|
+
}
|
|
631
|
+
if (!added) return current
|
|
632
|
+
return [...bySeq.values()].sort((a, b) => a.seq - b.seq)
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
/**
|
|
636
|
+
* The user's own messages in one conversation, oldest first.
|
|
637
|
+
*
|
|
638
|
+
* This is the "what did I ask" list. `readSurface` folds the *current model
|
|
639
|
+
* surface*, so a compacted conversation hides its older prompts; the complete
|
|
640
|
+
* list therefore comes from the raw log, read once and then topped up from the
|
|
641
|
+
* cheap surface read, which always contains the newest prompts.
|
|
642
|
+
* @returns `{ questions, count }` for the panel.
|
|
643
|
+
*/
|
|
644
|
+
async function questionsFor(ctx, sessionId) {
|
|
645
|
+
const query = ctx.sessionQuery
|
|
646
|
+
const cached = questionCache.get(sessionId)
|
|
647
|
+
const fresh = cached !== undefined && Date.now() - cached.at < QUESTIONS_CACHE_MS
|
|
648
|
+
let questions = []
|
|
649
|
+
|
|
650
|
+
let surfaceEvents = []
|
|
651
|
+
try {
|
|
652
|
+
const surface = await query.readSurface(sessionId)
|
|
653
|
+
surfaceEvents = surface !== null && surface !== undefined && Array.isArray(surface.events) ? surface.events : []
|
|
654
|
+
} catch {
|
|
655
|
+
surfaceEvents = []
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
if (fresh) {
|
|
659
|
+
questions = mergeQuestions(cached.questions, extractQuestions(surfaceEvents))
|
|
660
|
+
questionCache.set(sessionId, { at: cached.at, questions })
|
|
661
|
+
} else {
|
|
662
|
+
let events = []
|
|
663
|
+
try {
|
|
664
|
+
const log = await query.readSession(sessionId)
|
|
665
|
+
if (Array.isArray(log)) events = log
|
|
666
|
+
else if (log !== null && log !== undefined && Array.isArray(log.events)) events = log.events
|
|
667
|
+
} catch {
|
|
668
|
+
events = []
|
|
669
|
+
}
|
|
670
|
+
questions = events.length > 0 ? extractQuestions(events) : extractQuestions(surfaceEvents)
|
|
671
|
+
questionCache.set(sessionId, { at: Date.now(), questions })
|
|
672
|
+
while (questionCache.size > QUESTIONS_CACHE_MAX) {
|
|
673
|
+
const oldest = questionCache.keys().next()
|
|
674
|
+
if (oldest.done === true) break
|
|
675
|
+
questionCache.delete(oldest.value)
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
|
|
619
679
|
const tail = questions.length > QUESTIONS_MAX ? questions.slice(-QUESTIONS_MAX) : questions
|
|
620
680
|
return { questions: tail, count: questions.length }
|
|
621
681
|
}
|
|
622
682
|
//#endregion
|
|
683
|
+
//#endregion
|
|
623
684
|
|
|
624
685
|
//#region handler
|
|
625
686
|
async function handleApi(req, res, ctx) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-content-search-ad",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.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",
|