dsh-content-search-ad 0.22.1 → 0.23.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/README.md +4 -0
- package/client.js +83 -1
- package/index.js +64 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -63,6 +63,10 @@ is a subsequence, which turns the list into match-everything noise.
|
|
|
63
63
|
- Ordering is legible: more hits first, then the most recent match. Title-only
|
|
64
64
|
matches come last.
|
|
65
65
|
- **Recent searches** appear in the empty state; one click re-runs one.
|
|
66
|
+
- **This chat** is listed under them: every question **you** asked in the current
|
|
67
|
+
conversation, one row each (injected context and tool output are filtered out
|
|
68
|
+
by the message source). Clicking a row scrolls to that message in the
|
|
69
|
+
transcript and marks it red, paging history first when it is not loaded yet.
|
|
66
70
|
|
|
67
71
|
## The detail view
|
|
68
72
|
|
package/client.js
CHANGED
|
@@ -49,6 +49,7 @@ window.__ModuleLoader__.load({
|
|
|
49
49
|
'field.placeholder': 'Search the content of every conversation…',
|
|
50
50
|
'field.clear': 'Clear search',
|
|
51
51
|
'recent.title': 'Recent searches',
|
|
52
|
+
'questions.title': 'This chat · {n} questions',
|
|
52
53
|
'command.open': 'Search conversation content',
|
|
53
54
|
'hint.idle': 'Type a keyword to search every conversation body and title.',
|
|
54
55
|
'hint.shortcut': 'Press {keys} anywhere to open this panel.',
|
|
@@ -765,7 +766,10 @@ window.__ModuleLoader__.load({
|
|
|
765
766
|
.dcs-count{flex:0 0 auto;padding:0 6px;border-radius:999px;background:var(--dsw-alias-interactive-bg-hover-accent,var(--dsw-alias-bg-layer-3));font-size:11px;line-height:17px;font-variant-numeric:tabular-nums;color:var(--dsw-alias-label-secondary)}
|
|
766
767
|
.dcs-row-snippet{display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;font-size:12px;line-height:1.55;color:var(--dsw-alias-label-secondary);overflow-wrap:anywhere}
|
|
767
768
|
.dcs-row-meta{font-size:11px;color:var(--dsw-alias-label-tertiary);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
768
|
-
.dcs-chevron{flex:0 0 auto;color:var(--dsw-alias-label-tertiary);font-size:13px;line-height:1}.dcs-
|
|
769
|
+
.dcs-chevron{flex:0 0 auto;color:var(--dsw-alias-label-tertiary);font-size:13px;line-height:1}.dcs-questions{display:flex;flex-direction:column;gap:2px;padding:0 6px 6px}
|
|
770
|
+
.dcs-question{width:100%;box-sizing:border-box;padding:6px 8px;border:0;border-radius:var(--dsw-radius-sm);background:transparent;color:var(--dsw-alias-label-secondary);font:inherit;font-size:12px;line-height:1.5;text-align:left;cursor:pointer;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;overflow-wrap:anywhere}
|
|
771
|
+
.dcs-question:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}
|
|
772
|
+
.dcs-recent{display:flex;flex-wrap:wrap;gap:6px;padding:0 10px 4px}
|
|
769
773
|
.dcs-recent-chip{max-width:100%;padding:0 9px;height:24px;border:1px solid var(--dsw-alias-border-l2);border-radius:999px;background:transparent;color:var(--dsw-alias-label-secondary);font:inherit;font-size:12px;cursor:pointer;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
770
774
|
.dcs-recent-chip:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}
|
|
771
775
|
.dcs-scope{display:flex;gap:2px;margin-top:8px;padding:2px;border-radius:var(--dsw-radius-sm);background:var(--dsw-alias-bg-layer-1)}
|
|
@@ -980,6 +984,57 @@ window.__ModuleLoader__.load({
|
|
|
980
984
|
}
|
|
981
985
|
//#endregion
|
|
982
986
|
|
|
987
|
+
/**
|
|
988
|
+
* The user's own messages in this conversation, for the "what did I ask"
|
|
989
|
+
* list. The Host reads the log; the browser only renders the answer.
|
|
990
|
+
*/
|
|
991
|
+
async function fetchQuestions(sessionId, signal) {
|
|
992
|
+
if (typeof sessionId !== 'string' || sessionId.length === 0) return { questions: [], count: 0 }
|
|
993
|
+
const response = await fetch('/content-search/questions?focus=' + encodeURIComponent(sessionId), {
|
|
994
|
+
signal,
|
|
995
|
+
credentials: 'same-origin',
|
|
996
|
+
headers: { accept: 'application/json' },
|
|
997
|
+
})
|
|
998
|
+
if (!response.ok) throw new Error('questions unavailable (HTTP ' + response.status + ')')
|
|
999
|
+
const payload = await response.json()
|
|
1000
|
+
if (payload === null || typeof payload !== 'object' || payload.ok !== true) throw new Error('questions failed')
|
|
1001
|
+
const questions = Array.isArray(payload.questions) ? payload.questions : []
|
|
1002
|
+
return {
|
|
1003
|
+
count: typeof payload.count === 'number' ? payload.count : questions.length,
|
|
1004
|
+
questions: questions.map((question) => ({
|
|
1005
|
+
seq: question.seq,
|
|
1006
|
+
time: typeof question.time === 'number' ? question.time : 0,
|
|
1007
|
+
text: typeof question.text === 'string' ? question.text : '',
|
|
1008
|
+
anchor: typeof question.anchor === 'string' ? question.anchor : '',
|
|
1009
|
+
})),
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
/**
|
|
1014
|
+
* Center one question in the transcript, paging history to it when the
|
|
1015
|
+
* message is older than the loaded window.
|
|
1016
|
+
* @returns whether it was found immediately.
|
|
1017
|
+
*/
|
|
1018
|
+
function revealText(sessionId, anchor, seq) {
|
|
1019
|
+
if (typeof anchor !== 'string' || anchor.length < 4) return false
|
|
1020
|
+
ensureHighlightStyle()
|
|
1021
|
+
if (!highlightSupported()) return false
|
|
1022
|
+
const found = findAnchor(indexTranscript(true), anchor)
|
|
1023
|
+
if (found !== undefined) {
|
|
1024
|
+
CSS.highlights.set(ACTIVE_NAME, new Highlight(found.range))
|
|
1025
|
+
revealElement(found.element)
|
|
1026
|
+
return true
|
|
1027
|
+
}
|
|
1028
|
+
pageToHit(sessionId, seq).then((paged) => {
|
|
1029
|
+
if (!paged) return
|
|
1030
|
+
const retry = findAnchor(indexTranscript(true), anchor)
|
|
1031
|
+
if (retry === undefined) return
|
|
1032
|
+
CSS.highlights.set(ACTIVE_NAME, new Highlight(retry.range))
|
|
1033
|
+
revealElement(retry.element)
|
|
1034
|
+
}).catch(() => {})
|
|
1035
|
+
return false
|
|
1036
|
+
}
|
|
1037
|
+
|
|
983
1038
|
//#region component
|
|
984
1039
|
/**
|
|
985
1040
|
* Everything the panel needs to survive a tab remount: the sidebar is
|
|
@@ -1053,6 +1108,8 @@ window.__ModuleLoader__.load({
|
|
|
1053
1108
|
setScopeState(value)
|
|
1054
1109
|
}, [])
|
|
1055
1110
|
const [recent, setRecent] = React.useState(readRecent)
|
|
1111
|
+
const [questions, setQuestions] = React.useState([])
|
|
1112
|
+
const [questionCount, setQuestionCount] = React.useState(0)
|
|
1056
1113
|
|
|
1057
1114
|
const subscribeList = React.useCallback((notify) => {
|
|
1058
1115
|
const store = runtime === null ? undefined : runtime.sessions && runtime.sessions.list
|
|
@@ -1093,6 +1150,18 @@ window.__ModuleLoader__.load({
|
|
|
1093
1150
|
if (activeInput === inputRef.current) activeInput = null
|
|
1094
1151
|
}
|
|
1095
1152
|
}, [])
|
|
1153
|
+
// The "what did I ask" list belongs to the conversation this panel is on.
|
|
1154
|
+
React.useEffect(() => {
|
|
1155
|
+
if (typeof focusSessionId !== 'string' || focusSessionId.length === 0) return undefined
|
|
1156
|
+
const controller = new AbortController()
|
|
1157
|
+
fetchQuestions(focusSessionId, controller.signal).then((outcome) => {
|
|
1158
|
+
if (controller.signal.aborted) return
|
|
1159
|
+
setQuestions(outcome.questions)
|
|
1160
|
+
setQuestionCount(outcome.count)
|
|
1161
|
+
}).catch(() => {})
|
|
1162
|
+
return () => controller.abort()
|
|
1163
|
+
}, [focusSessionId])
|
|
1164
|
+
|
|
1096
1165
|
const trimmed = query.trim()
|
|
1097
1166
|
|
|
1098
1167
|
React.useEffect(() => {
|
|
@@ -1341,6 +1410,19 @@ window.__ModuleLoader__.load({
|
|
|
1341
1410
|
},
|
|
1342
1411
|
}, value))))
|
|
1343
1412
|
}
|
|
1413
|
+
if (questions.length > 0) {
|
|
1414
|
+
body.push(h('p', { key: 'questions-title', className: 'dcs-section' },
|
|
1415
|
+
t('questions.title', { n: questionCount })))
|
|
1416
|
+
body.push(h('div', { key: 'questions', className: 'dcs-questions' }, questions.map((question, index) => h('button', {
|
|
1417
|
+
key: String(question.seq) + ':' + index,
|
|
1418
|
+
type: 'button',
|
|
1419
|
+
className: 'dcs-question',
|
|
1420
|
+
title: question.text,
|
|
1421
|
+
onClick: () => {
|
|
1422
|
+
revealText(focusSessionId, question.anchor, question.seq)
|
|
1423
|
+
},
|
|
1424
|
+
}, question.text))))
|
|
1425
|
+
}
|
|
1344
1426
|
} else if (phase === 'ready' && ordered.length === 0) {
|
|
1345
1427
|
body.push(h('p', { key: 'empty', className: 'dcs-note' }, t('hint.empty')))
|
|
1346
1428
|
} else {
|
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.23.0'
|
|
68
68
|
|
|
69
69
|
//#region http helpers
|
|
70
70
|
function writeJson(res, status, value) {
|
|
@@ -569,6 +569,58 @@ async function scanCorpus(ctx, parsed, focusId, scope) {
|
|
|
569
569
|
}
|
|
570
570
|
//#endregion
|
|
571
571
|
|
|
572
|
+
//#region questions
|
|
573
|
+
/** How many user messages the panel lists for one conversation. */
|
|
574
|
+
const QUESTIONS_MAX = 200
|
|
575
|
+
/** Longest question text sent for display. */
|
|
576
|
+
const QUESTION_TEXT_CHARS = 220
|
|
577
|
+
/** Longest anchor sent for locating the question in the transcript. */
|
|
578
|
+
const QUESTION_ANCHOR_CHARS = 80
|
|
579
|
+
|
|
580
|
+
/**
|
|
581
|
+
* The user's own messages in one conversation, oldest first.
|
|
582
|
+
*
|
|
583
|
+
* This is the "what did I ask" list: only `user/message` events, only their
|
|
584
|
+
* text blocks, displayed as written and anchored for the transcript locator.
|
|
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 : []
|
|
591
|
+
const questions = []
|
|
592
|
+
for (const event of events) {
|
|
593
|
+
if (event === null || typeof event !== 'object' || event.type !== 'user/message') continue
|
|
594
|
+
const data = event.data === null || event.data === undefined ? {} : event.data
|
|
595
|
+
// Injected context also arrives as a user message; only the human `user`
|
|
596
|
+
// source counts as something the person actually asked.
|
|
597
|
+
const source = data.source === null || data.source === undefined ? {} : data.source
|
|
598
|
+
if (source.kind !== 'user') continue
|
|
599
|
+
const content = data.content
|
|
600
|
+
if (!Array.isArray(content)) continue
|
|
601
|
+
const parts = []
|
|
602
|
+
for (const block of content) {
|
|
603
|
+
if (block === null || typeof block !== 'object') continue
|
|
604
|
+
if (block.type !== 'text') continue
|
|
605
|
+
if (typeof block.text !== 'string' || block.text.length === 0) continue
|
|
606
|
+
parts.push(block.text)
|
|
607
|
+
}
|
|
608
|
+
if (parts.length === 0) continue
|
|
609
|
+
const raw = parts.join('\n').replace(/\s+/gu, ' ').trim()
|
|
610
|
+
if (raw.length === 0) continue
|
|
611
|
+
const plain = plainOf(parts.join('\n'))
|
|
612
|
+
questions.push({
|
|
613
|
+
seq: event.seq,
|
|
614
|
+
time: typeof event.time === 'number' ? event.time : 0,
|
|
615
|
+
text: raw.slice(0, QUESTION_TEXT_CHARS),
|
|
616
|
+
anchor: plain.slice(0, QUESTION_ANCHOR_CHARS),
|
|
617
|
+
})
|
|
618
|
+
}
|
|
619
|
+
const tail = questions.length > QUESTIONS_MAX ? questions.slice(-QUESTIONS_MAX) : questions
|
|
620
|
+
return { questions: tail, count: questions.length }
|
|
621
|
+
}
|
|
622
|
+
//#endregion
|
|
623
|
+
|
|
572
624
|
//#region handler
|
|
573
625
|
async function handleApi(req, res, ctx) {
|
|
574
626
|
if (!isTrustedRequest(req)) {
|
|
@@ -619,6 +671,17 @@ async function handleApi(req, res, ctx) {
|
|
|
619
671
|
return
|
|
620
672
|
}
|
|
621
673
|
|
|
674
|
+
if (route === '/questions' && req.method === 'GET') {
|
|
675
|
+
const focusId = url.searchParams.get('focus')
|
|
676
|
+
if (typeof focusId !== 'string' || focusId.length === 0) {
|
|
677
|
+
fail(res, 400, 'focus-required', 'the focus parameter is required')
|
|
678
|
+
return
|
|
679
|
+
}
|
|
680
|
+
const outcome = await questionsFor(ctx, focusId)
|
|
681
|
+
writeJson(res, 200, { ok: true, sessionId: focusId, ...outcome })
|
|
682
|
+
return
|
|
683
|
+
}
|
|
684
|
+
|
|
622
685
|
fail(res, 404, 'not-found', 'unknown route')
|
|
623
686
|
}
|
|
624
687
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-content-search-ad",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.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",
|