dsh-content-search-ad 0.25.0 → 0.25.2
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 +2 -2
- 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.25.
|
|
22
|
+
const PLUGIN_VERSION = '0.25.2'
|
|
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. */
|
|
@@ -1245,7 +1245,7 @@ window.__ModuleLoader__.load({
|
|
|
1245
1245
|
setQuestions((current) => (current.length === outcome.questions.length ? current : outcome.questions))
|
|
1246
1246
|
setQuestionCount(outcome.count)
|
|
1247
1247
|
}).catch(() => {})
|
|
1248
|
-
},
|
|
1248
|
+
}, 20000)
|
|
1249
1249
|
return () => clearInterval(timer)
|
|
1250
1250
|
}, [focusSessionId])
|
|
1251
1251
|
|
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.25.
|
|
67
|
+
const VERSION = '0.25.2'
|
|
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.25.
|
|
3
|
+
"version": "0.25.2",
|
|
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",
|