dsh-mega-chat-nav 0.1.1
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/LICENSE +201 -0
- package/README.en.md +149 -0
- package/README.md +149 -0
- package/cordis.patch.yml +4 -0
- package/lib/client/NavOverlay.js +35 -0
- package/lib/client/NavRail.js +12 -0
- package/lib/client/QuestionNavSettingsTab.js +26 -0
- package/lib/client/QuestionNavStrip.js +555 -0
- package/lib/client/components/ConfigPanel.js +14 -0
- package/lib/client/components/DotRail.js +62 -0
- package/lib/client/components/NavOverlay.js +121 -0
- package/lib/client/components/NavRail.js +97 -0
- package/lib/client/components/RailDispatch.js +22 -0
- package/lib/client/components/RailHost.js +79 -0
- package/lib/client/components/SearchBox.js +66 -0
- package/lib/client/components/SettingsPage.js +46 -0
- package/lib/client/components/StandaloneSettings.js +16 -0
- package/lib/client/components/codex/CodexRail.js +139 -0
- package/lib/client/components/deepseek/DeepseekRail.js +264 -0
- package/lib/client/components/minimal/MinimalRail.js +135 -0
- package/lib/client/components/minimal/cards.js +32 -0
- package/lib/client/components/minimal/dot.js +11 -0
- package/lib/client/components/minimal/hint.js +30 -0
- package/lib/client/components/minimal/paging.js +5 -0
- package/lib/client/components/minimal/quick-settings.js +28 -0
- package/lib/client/components/minimal/search.js +67 -0
- package/lib/client/components/minimal/useRail.js +716 -0
- package/lib/client/components/rail/cards.js +32 -0
- package/lib/client/components/rail/hint.js +30 -0
- package/lib/client/components/rail/paging.js +5 -0
- package/lib/client/components/rail/quick-settings.js +28 -0
- package/lib/client/components/rail/search.js +76 -0
- package/lib/client/components/rail/useRail.js +845 -0
- package/lib/client/components/settings/SettingsPage.js +46 -0
- package/lib/client/components/settings/SettingsTab.js +17 -0
- package/lib/client/components/settings/StandaloneSettings.js +16 -0
- package/lib/client/components/shared/Cascade.js +26 -0
- package/lib/client/components/shared/ConfigPanel.js +27 -0
- package/lib/client/components/shared/Dot.js +8 -0
- package/lib/client/components/shared/Hint.js +5 -0
- package/lib/client/components/shared/PagingButton.js +5 -0
- package/lib/client/components/shared/RailShell.js +78 -0
- package/lib/client/components/shared/SearchBox.js +63 -0
- package/lib/client/components/shared/hooks.js +427 -0
- package/lib/client/components/shared/types.js +1 -0
- package/lib/client/config.js +1 -0
- package/lib/client/engines/jump.js +34 -0
- package/lib/client/engines/useAtBottom.js +25 -0
- package/lib/client/engines/useJump.js +40 -0
- package/lib/client/engines/useScrollSpy.js +88 -0
- package/lib/client/hooks.js +11 -0
- package/lib/client/index.js +312 -0
- package/lib/client/jump.js +255 -0
- package/lib/client/locales.js +142 -0
- package/lib/client/pure.js +61 -0
- package/lib/client/settings.js +369 -0
- package/lib/client/virtual/VirtualList.js +21 -0
- package/lib/client.js +3213 -0
- package/lib/compat.js +145 -0
- package/lib/config.js +37 -0
- package/lib/core/active-dot.js +17 -0
- package/lib/core/align.js +9 -0
- package/lib/core/config.js +37 -0
- package/lib/core/focus.js +38 -0
- package/lib/core/jump.js +98 -0
- package/lib/core/logic/active-dot.js +16 -0
- package/lib/core/logic/focus.js +34 -0
- package/lib/core/logic/jump.js +188 -0
- package/lib/core/logic/nodes.js +59 -0
- package/lib/core/model/nav-item.js +1 -0
- package/lib/core/model/turns.js +73 -0
- package/lib/core/nav-item.js +1 -0
- package/lib/core/nodes.js +57 -0
- package/lib/core/page-size.js +7 -0
- package/lib/core/question-entry.js +1 -0
- package/lib/core/time.js +23 -0
- package/lib/core/turn-dots.js +85 -0
- package/lib/core/utils/measure.js +24 -0
- package/lib/core/utils/time.js +26 -0
- package/lib/index.js +64 -0
- package/lib/nav-item.js +1 -0
- package/lib/nodes.js +59 -0
- package/lib/projection.js +126 -0
- package/lib/schema.js +26 -0
- package/lib/search.js +285 -0
- package/lib/settings.js +89 -0
- package/lib/types/client/NavOverlay.d.ts +18 -0
- package/lib/types/client/NavRail.d.ts +7 -0
- package/lib/types/client/QuestionNavSettingsTab.d.ts +16 -0
- package/lib/types/client/QuestionNavStrip.d.ts +48 -0
- package/lib/types/client/components/ConfigPanel.d.ts +14 -0
- package/lib/types/client/components/DotRail.d.ts +15 -0
- package/lib/types/client/components/NavOverlay.d.ts +30 -0
- package/lib/types/client/components/NavRail.d.ts +16 -0
- package/lib/types/client/components/RailDispatch.d.ts +8 -0
- package/lib/types/client/components/RailHost.d.ts +27 -0
- package/lib/types/client/components/SearchBox.d.ts +9 -0
- package/lib/types/client/components/SettingsPage.d.ts +9 -0
- package/lib/types/client/components/StandaloneSettings.d.ts +13 -0
- package/lib/types/client/components/codex/CodexRail.d.ts +3 -0
- package/lib/types/client/components/deepseek/DeepseekRail.d.ts +3 -0
- package/lib/types/client/components/minimal/MinimalRail.d.ts +8 -0
- package/lib/types/client/components/minimal/cards.d.ts +19 -0
- package/lib/types/client/components/minimal/dot.d.ts +14 -0
- package/lib/types/client/components/minimal/hint.d.ts +11 -0
- package/lib/types/client/components/minimal/paging.d.ts +10 -0
- package/lib/types/client/components/minimal/quick-settings.d.ts +8 -0
- package/lib/types/client/components/minimal/search.d.ts +27 -0
- package/lib/types/client/components/minimal/useRail.d.ts +90 -0
- package/lib/types/client/components/rail/cards.d.ts +19 -0
- package/lib/types/client/components/rail/hint.d.ts +11 -0
- package/lib/types/client/components/rail/paging.d.ts +10 -0
- package/lib/types/client/components/rail/quick-settings.d.ts +8 -0
- package/lib/types/client/components/rail/search.d.ts +34 -0
- package/lib/types/client/components/rail/useRail.d.ts +132 -0
- package/lib/types/client/components/settings/SettingsPage.d.ts +9 -0
- package/lib/types/client/components/settings/SettingsTab.d.ts +6 -0
- package/lib/types/client/components/settings/StandaloneSettings.d.ts +13 -0
- package/lib/types/client/components/shared/Cascade.d.ts +14 -0
- package/lib/types/client/components/shared/ConfigPanel.d.ts +8 -0
- package/lib/types/client/components/shared/Dot.d.ts +17 -0
- package/lib/types/client/components/shared/Hint.d.ts +6 -0
- package/lib/types/client/components/shared/PagingButton.d.ts +10 -0
- package/lib/types/client/components/shared/RailShell.d.ts +43 -0
- package/lib/types/client/components/shared/SearchBox.d.ts +18 -0
- package/lib/types/client/components/shared/hooks.d.ts +64 -0
- package/lib/types/client/components/shared/types.d.ts +101 -0
- package/lib/types/client/config.d.ts +9 -0
- package/lib/types/client/engines/jump.d.ts +17 -0
- package/lib/types/client/engines/useAtBottom.d.ts +1 -0
- package/lib/types/client/engines/useJump.d.ts +16 -0
- package/lib/types/client/engines/useScrollSpy.d.ts +12 -0
- package/lib/types/client/hooks.d.ts +7 -0
- package/lib/types/client/index.d.ts +31 -0
- package/lib/types/client/jump.d.ts +47 -0
- package/lib/types/client/locales.d.ts +142 -0
- package/lib/types/client/pure.d.ts +21 -0
- package/lib/types/client/settings.d.ts +173 -0
- package/lib/types/client/virtual/VirtualList.d.ts +15 -0
- package/lib/types/compat.d.ts +44 -0
- package/lib/types/config.d.ts +44 -0
- package/lib/types/core/active-dot.d.ts +15 -0
- package/lib/types/core/align.d.ts +10 -0
- package/lib/types/core/config.d.ts +44 -0
- package/lib/types/core/focus.d.ts +24 -0
- package/lib/types/core/jump.d.ts +39 -0
- package/lib/types/core/logic/active-dot.d.ts +15 -0
- package/lib/types/core/logic/focus.d.ts +22 -0
- package/lib/types/core/logic/jump.d.ts +39 -0
- package/lib/types/core/logic/nodes.d.ts +48 -0
- package/lib/types/core/model/nav-item.d.ts +12 -0
- package/lib/types/core/model/turns.d.ts +30 -0
- package/lib/types/core/nav-item.d.ts +12 -0
- package/lib/types/core/nodes.d.ts +43 -0
- package/lib/types/core/page-size.d.ts +8 -0
- package/lib/types/core/question-entry.d.ts +12 -0
- package/lib/types/core/time.d.ts +4 -0
- package/lib/types/core/turn-dots.d.ts +29 -0
- package/lib/types/core/utils/measure.d.ts +12 -0
- package/lib/types/core/utils/time.d.ts +4 -0
- package/lib/types/index.d.ts +4 -0
- package/lib/types/nav-item.d.ts +12 -0
- package/lib/types/nodes.d.ts +48 -0
- package/lib/types/projection.d.ts +71 -0
- package/lib/types/schema.d.ts +37 -0
- package/lib/types/search.d.ts +42 -0
- package/lib/types/settings.d.ts +99 -0
- package/package.json +71 -0
- package/src/client/components/RailDispatch.tsx +27 -0
- package/src/client/components/codex/CodexRail.tsx +348 -0
- package/src/client/components/deepseek/DeepseekRail.tsx +522 -0
- package/src/client/components/minimal/MinimalRail.tsx +324 -0
- package/src/client/components/minimal/dot.tsx +32 -0
- package/src/client/components/rail/cards.tsx +102 -0
- package/src/client/components/rail/hint.tsx +50 -0
- package/src/client/components/rail/paging.tsx +26 -0
- package/src/client/components/rail/quick-settings.tsx +130 -0
- package/src/client/components/rail/search.tsx +147 -0
- package/src/client/components/rail/useRail.ts +906 -0
- package/src/client/components/settings/SettingsPage.tsx +198 -0
- package/src/client/components/settings/StandaloneSettings.tsx +28 -0
- package/src/client/components/shared/types.ts +99 -0
- package/src/client/index.ts +388 -0
- package/src/client/jump.ts +293 -0
- package/src/client/locales.ts +143 -0
- package/src/client/settings.ts +482 -0
- package/src/client/styles.css +1580 -0
- package/src/compat.ts +161 -0
- package/src/index.ts +66 -0
- package/src/projection.ts +174 -0
- package/src/search.ts +291 -0
- package/src/settings.ts +169 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
// 搜索浮层:输入防抖 → host 检索 → 结果(tag 用户/AI + 轮次标题 + 两行预览 + 历史提示)
|
|
2
|
+
import { useCallback, useEffect, useRef, useState, type ReactNode } from 'react'
|
|
3
|
+
import type { Translate } from '../shared/types.ts'
|
|
4
|
+
import { clockText } from './useRail.ts'
|
|
5
|
+
|
|
6
|
+
export interface SearchHit {
|
|
7
|
+
key: string
|
|
8
|
+
seq: number
|
|
9
|
+
time: number
|
|
10
|
+
role: string
|
|
11
|
+
/** 命中消息所在轮次(host 由 turn/start 计数;未定位为 0) */
|
|
12
|
+
turn: number
|
|
13
|
+
/** 命中是否来自更早历史 */
|
|
14
|
+
historic: boolean
|
|
15
|
+
snippet: string
|
|
16
|
+
hitStart: number
|
|
17
|
+
hitLen: number
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface SearchBoxProps {
|
|
21
|
+
sessionId?: string
|
|
22
|
+
t: Translate
|
|
23
|
+
/** 搜索内容范围(多选;host 按此过滤) */
|
|
24
|
+
scopes: readonly string[]
|
|
25
|
+
/** 点击命中:key = 完整 DOM 锚点 key(host 按消息 kind 拼好);seq = 方向判定序号 */
|
|
26
|
+
onJump: (key: string, seq: number) => void
|
|
27
|
+
onClose: () => void
|
|
28
|
+
/** 查询为空时显示的内容(如全部轮次列表);缺省显示空区域 */
|
|
29
|
+
emptyContent?: ReactNode
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** 检索:携带 AbortController 的 host 请求(scopes 过滤由 host 执行) */
|
|
33
|
+
/**
|
|
34
|
+
* 检索 + 统一排序:host 按日志顺序返回,此处统一按轮次倒序(最新轮在上;
|
|
35
|
+
* 同轮按 seq 倒序——最新消息在前)。minimal/codex 浮层、deepseek 面板与移动抽屉共用,
|
|
36
|
+
* 保证三种风格与搜索抽屉的命中顺序一致。
|
|
37
|
+
*/
|
|
38
|
+
export function fetchHits(sessionId: string | undefined, query: string, scopes: readonly string[], signal: AbortSignal): Promise<SearchHit[]> {
|
|
39
|
+
const url = '/mega-chat-nav/search?session=' + encodeURIComponent(sessionId ?? '')
|
|
40
|
+
+ '&q=' + encodeURIComponent(query)
|
|
41
|
+
+ '&scopes=' + encodeURIComponent(scopes.join(',')) // 不传 limit → host 返回全部命中
|
|
42
|
+
return fetch(url, { signal })
|
|
43
|
+
.then((resp) => resp.json() as Promise<{ ok?: boolean; hits?: SearchHit[] }>)
|
|
44
|
+
.then((data) => {
|
|
45
|
+
const hits = data.ok === true ? (data.hits ?? []) : []
|
|
46
|
+
return hits.sort((x, y) => (y.turn - x.turn) || (y.seq - x.seq))
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** 角色 → 标签文本(用户/助手/工具;steering 归用户侧) */
|
|
51
|
+
function roleTag(role: string, t: Translate): string {
|
|
52
|
+
if (role === 'assistant') return t('search.tag.assistant')
|
|
53
|
+
if (role === 'tool') return t('search.tag.tool')
|
|
54
|
+
return t('search.tag.user')
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function SearchBox(props: SearchBoxProps): ReactNode {
|
|
58
|
+
const [query, setQuery] = useState('')
|
|
59
|
+
const [results, setResults] = useState<SearchHit[]>([])
|
|
60
|
+
const [busy, setBusy] = useState(false)
|
|
61
|
+
const abortRef = useRef<AbortController | null>(null)
|
|
62
|
+
const debounceRef = useRef<number | null>(null)
|
|
63
|
+
const inputRef = useRef<HTMLInputElement | null>(null)
|
|
64
|
+
|
|
65
|
+
const run = useCallback((raw: string) => {
|
|
66
|
+
abortRef.current?.abort()
|
|
67
|
+
const ac = new AbortController()
|
|
68
|
+
abortRef.current = ac
|
|
69
|
+
const q = raw.trim()
|
|
70
|
+
if (q.length < 1) { setResults([]); setBusy(false); return }
|
|
71
|
+
setBusy(true)
|
|
72
|
+
fetchHits(props.sessionId, q, props.scopes, ac.signal)
|
|
73
|
+
.then((hits) => {
|
|
74
|
+
setResults(hits) // fetchHits 已按轮次倒序返回
|
|
75
|
+
})
|
|
76
|
+
.catch((e: unknown) => {
|
|
77
|
+
if ((e as { name?: string }).name !== 'AbortError') setResults([])
|
|
78
|
+
})
|
|
79
|
+
.finally(() => setBusy(false))
|
|
80
|
+
}, [props.sessionId, props.scopes])
|
|
81
|
+
|
|
82
|
+
const onType = (value: string): void => {
|
|
83
|
+
setQuery(value)
|
|
84
|
+
if (debounceRef.current !== null) window.clearTimeout(debounceRef.current)
|
|
85
|
+
// 250ms 防抖:连续输入只触发一次检索
|
|
86
|
+
debounceRef.current = window.setTimeout(() => run(value), 250)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
useEffect(() => {
|
|
90
|
+
inputRef.current?.focus()
|
|
91
|
+
return () => {
|
|
92
|
+
if (debounceRef.current !== null) window.clearTimeout(debounceRef.current)
|
|
93
|
+
abortRef.current?.abort()
|
|
94
|
+
}
|
|
95
|
+
}, [])
|
|
96
|
+
|
|
97
|
+
const historicCount = results.filter((hit) => hit.historic).length
|
|
98
|
+
|
|
99
|
+
return (
|
|
100
|
+
<div className="mgcn-search" role="dialog" aria-label={props.t('search.placeholder')}>
|
|
101
|
+
<input
|
|
102
|
+
ref={inputRef}
|
|
103
|
+
className="mgcn-search-input"
|
|
104
|
+
value={query}
|
|
105
|
+
placeholder={props.t('search.placeholder')}
|
|
106
|
+
onChange={(e) => onType(e.target.value)}
|
|
107
|
+
onKeyDown={(e) => { if (e.key === 'Escape') props.onClose() }}
|
|
108
|
+
/>
|
|
109
|
+
{busy ? <div className="mgcn-search-busy">…</div> : null}
|
|
110
|
+
{!busy && query.trim() === '' && props.emptyContent !== undefined ? props.emptyContent : null}
|
|
111
|
+
{!busy && results.length > 0 && historicCount > 0 ? (
|
|
112
|
+
<div className="mgcn-search-historic">{props.t('search.historic', { n: historicCount })}</div>
|
|
113
|
+
) : null}
|
|
114
|
+
{results.length > 0 ? (
|
|
115
|
+
<div className="mgcn-search-results">
|
|
116
|
+
{results.map((hit) => (
|
|
117
|
+
<button
|
|
118
|
+
key={hit.key + ':' + hit.seq}
|
|
119
|
+
type="button"
|
|
120
|
+
className="mgcn-search-hit"
|
|
121
|
+
onClick={() => props.onJump(hit.key, hit.seq)}
|
|
122
|
+
>
|
|
123
|
+
<span className="mgcn-search-title">
|
|
124
|
+
<span className="mgcn-search-titleLeft">
|
|
125
|
+
{hit.turn > 0 ? <span className="mgcn-search-turn">{props.t('search.turnTitle', { turn: hit.turn })}</span> : null}
|
|
126
|
+
<span className={'mgcn-search-tag mgcn-search-tag--' + hit.role}>{roleTag(hit.role, props.t)}</span>
|
|
127
|
+
</span>
|
|
128
|
+
<span className="mgcn-search-titleTime">{clockText(hit.time, Date.now())}</span>
|
|
129
|
+
</span>
|
|
130
|
+
<span className="mgcn-search-body">
|
|
131
|
+
<span className="mgcn-search-text">
|
|
132
|
+
{hit.hitStart >= 0 && hit.hitLen > 0 ? (
|
|
133
|
+
<>
|
|
134
|
+
{hit.snippet.slice(0, hit.hitStart)}
|
|
135
|
+
<mark className="mgcn-search-mark">{hit.snippet.slice(hit.hitStart, hit.hitStart + hit.hitLen)}</mark>
|
|
136
|
+
{hit.snippet.slice(hit.hitStart + hit.hitLen)}
|
|
137
|
+
</>
|
|
138
|
+
) : hit.snippet}
|
|
139
|
+
</span>
|
|
140
|
+
</span>
|
|
141
|
+
</button>
|
|
142
|
+
))}
|
|
143
|
+
</div>
|
|
144
|
+
) : null}
|
|
145
|
+
</div>
|
|
146
|
+
)
|
|
147
|
+
}
|