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.
Files changed (192) hide show
  1. package/LICENSE +201 -0
  2. package/README.en.md +149 -0
  3. package/README.md +149 -0
  4. package/cordis.patch.yml +4 -0
  5. package/lib/client/NavOverlay.js +35 -0
  6. package/lib/client/NavRail.js +12 -0
  7. package/lib/client/QuestionNavSettingsTab.js +26 -0
  8. package/lib/client/QuestionNavStrip.js +555 -0
  9. package/lib/client/components/ConfigPanel.js +14 -0
  10. package/lib/client/components/DotRail.js +62 -0
  11. package/lib/client/components/NavOverlay.js +121 -0
  12. package/lib/client/components/NavRail.js +97 -0
  13. package/lib/client/components/RailDispatch.js +22 -0
  14. package/lib/client/components/RailHost.js +79 -0
  15. package/lib/client/components/SearchBox.js +66 -0
  16. package/lib/client/components/SettingsPage.js +46 -0
  17. package/lib/client/components/StandaloneSettings.js +16 -0
  18. package/lib/client/components/codex/CodexRail.js +139 -0
  19. package/lib/client/components/deepseek/DeepseekRail.js +264 -0
  20. package/lib/client/components/minimal/MinimalRail.js +135 -0
  21. package/lib/client/components/minimal/cards.js +32 -0
  22. package/lib/client/components/minimal/dot.js +11 -0
  23. package/lib/client/components/minimal/hint.js +30 -0
  24. package/lib/client/components/minimal/paging.js +5 -0
  25. package/lib/client/components/minimal/quick-settings.js +28 -0
  26. package/lib/client/components/minimal/search.js +67 -0
  27. package/lib/client/components/minimal/useRail.js +716 -0
  28. package/lib/client/components/rail/cards.js +32 -0
  29. package/lib/client/components/rail/hint.js +30 -0
  30. package/lib/client/components/rail/paging.js +5 -0
  31. package/lib/client/components/rail/quick-settings.js +28 -0
  32. package/lib/client/components/rail/search.js +76 -0
  33. package/lib/client/components/rail/useRail.js +845 -0
  34. package/lib/client/components/settings/SettingsPage.js +46 -0
  35. package/lib/client/components/settings/SettingsTab.js +17 -0
  36. package/lib/client/components/settings/StandaloneSettings.js +16 -0
  37. package/lib/client/components/shared/Cascade.js +26 -0
  38. package/lib/client/components/shared/ConfigPanel.js +27 -0
  39. package/lib/client/components/shared/Dot.js +8 -0
  40. package/lib/client/components/shared/Hint.js +5 -0
  41. package/lib/client/components/shared/PagingButton.js +5 -0
  42. package/lib/client/components/shared/RailShell.js +78 -0
  43. package/lib/client/components/shared/SearchBox.js +63 -0
  44. package/lib/client/components/shared/hooks.js +427 -0
  45. package/lib/client/components/shared/types.js +1 -0
  46. package/lib/client/config.js +1 -0
  47. package/lib/client/engines/jump.js +34 -0
  48. package/lib/client/engines/useAtBottom.js +25 -0
  49. package/lib/client/engines/useJump.js +40 -0
  50. package/lib/client/engines/useScrollSpy.js +88 -0
  51. package/lib/client/hooks.js +11 -0
  52. package/lib/client/index.js +312 -0
  53. package/lib/client/jump.js +255 -0
  54. package/lib/client/locales.js +142 -0
  55. package/lib/client/pure.js +61 -0
  56. package/lib/client/settings.js +369 -0
  57. package/lib/client/virtual/VirtualList.js +21 -0
  58. package/lib/client.js +3213 -0
  59. package/lib/compat.js +145 -0
  60. package/lib/config.js +37 -0
  61. package/lib/core/active-dot.js +17 -0
  62. package/lib/core/align.js +9 -0
  63. package/lib/core/config.js +37 -0
  64. package/lib/core/focus.js +38 -0
  65. package/lib/core/jump.js +98 -0
  66. package/lib/core/logic/active-dot.js +16 -0
  67. package/lib/core/logic/focus.js +34 -0
  68. package/lib/core/logic/jump.js +188 -0
  69. package/lib/core/logic/nodes.js +59 -0
  70. package/lib/core/model/nav-item.js +1 -0
  71. package/lib/core/model/turns.js +73 -0
  72. package/lib/core/nav-item.js +1 -0
  73. package/lib/core/nodes.js +57 -0
  74. package/lib/core/page-size.js +7 -0
  75. package/lib/core/question-entry.js +1 -0
  76. package/lib/core/time.js +23 -0
  77. package/lib/core/turn-dots.js +85 -0
  78. package/lib/core/utils/measure.js +24 -0
  79. package/lib/core/utils/time.js +26 -0
  80. package/lib/index.js +64 -0
  81. package/lib/nav-item.js +1 -0
  82. package/lib/nodes.js +59 -0
  83. package/lib/projection.js +126 -0
  84. package/lib/schema.js +26 -0
  85. package/lib/search.js +285 -0
  86. package/lib/settings.js +89 -0
  87. package/lib/types/client/NavOverlay.d.ts +18 -0
  88. package/lib/types/client/NavRail.d.ts +7 -0
  89. package/lib/types/client/QuestionNavSettingsTab.d.ts +16 -0
  90. package/lib/types/client/QuestionNavStrip.d.ts +48 -0
  91. package/lib/types/client/components/ConfigPanel.d.ts +14 -0
  92. package/lib/types/client/components/DotRail.d.ts +15 -0
  93. package/lib/types/client/components/NavOverlay.d.ts +30 -0
  94. package/lib/types/client/components/NavRail.d.ts +16 -0
  95. package/lib/types/client/components/RailDispatch.d.ts +8 -0
  96. package/lib/types/client/components/RailHost.d.ts +27 -0
  97. package/lib/types/client/components/SearchBox.d.ts +9 -0
  98. package/lib/types/client/components/SettingsPage.d.ts +9 -0
  99. package/lib/types/client/components/StandaloneSettings.d.ts +13 -0
  100. package/lib/types/client/components/codex/CodexRail.d.ts +3 -0
  101. package/lib/types/client/components/deepseek/DeepseekRail.d.ts +3 -0
  102. package/lib/types/client/components/minimal/MinimalRail.d.ts +8 -0
  103. package/lib/types/client/components/minimal/cards.d.ts +19 -0
  104. package/lib/types/client/components/minimal/dot.d.ts +14 -0
  105. package/lib/types/client/components/minimal/hint.d.ts +11 -0
  106. package/lib/types/client/components/minimal/paging.d.ts +10 -0
  107. package/lib/types/client/components/minimal/quick-settings.d.ts +8 -0
  108. package/lib/types/client/components/minimal/search.d.ts +27 -0
  109. package/lib/types/client/components/minimal/useRail.d.ts +90 -0
  110. package/lib/types/client/components/rail/cards.d.ts +19 -0
  111. package/lib/types/client/components/rail/hint.d.ts +11 -0
  112. package/lib/types/client/components/rail/paging.d.ts +10 -0
  113. package/lib/types/client/components/rail/quick-settings.d.ts +8 -0
  114. package/lib/types/client/components/rail/search.d.ts +34 -0
  115. package/lib/types/client/components/rail/useRail.d.ts +132 -0
  116. package/lib/types/client/components/settings/SettingsPage.d.ts +9 -0
  117. package/lib/types/client/components/settings/SettingsTab.d.ts +6 -0
  118. package/lib/types/client/components/settings/StandaloneSettings.d.ts +13 -0
  119. package/lib/types/client/components/shared/Cascade.d.ts +14 -0
  120. package/lib/types/client/components/shared/ConfigPanel.d.ts +8 -0
  121. package/lib/types/client/components/shared/Dot.d.ts +17 -0
  122. package/lib/types/client/components/shared/Hint.d.ts +6 -0
  123. package/lib/types/client/components/shared/PagingButton.d.ts +10 -0
  124. package/lib/types/client/components/shared/RailShell.d.ts +43 -0
  125. package/lib/types/client/components/shared/SearchBox.d.ts +18 -0
  126. package/lib/types/client/components/shared/hooks.d.ts +64 -0
  127. package/lib/types/client/components/shared/types.d.ts +101 -0
  128. package/lib/types/client/config.d.ts +9 -0
  129. package/lib/types/client/engines/jump.d.ts +17 -0
  130. package/lib/types/client/engines/useAtBottom.d.ts +1 -0
  131. package/lib/types/client/engines/useJump.d.ts +16 -0
  132. package/lib/types/client/engines/useScrollSpy.d.ts +12 -0
  133. package/lib/types/client/hooks.d.ts +7 -0
  134. package/lib/types/client/index.d.ts +31 -0
  135. package/lib/types/client/jump.d.ts +47 -0
  136. package/lib/types/client/locales.d.ts +142 -0
  137. package/lib/types/client/pure.d.ts +21 -0
  138. package/lib/types/client/settings.d.ts +173 -0
  139. package/lib/types/client/virtual/VirtualList.d.ts +15 -0
  140. package/lib/types/compat.d.ts +44 -0
  141. package/lib/types/config.d.ts +44 -0
  142. package/lib/types/core/active-dot.d.ts +15 -0
  143. package/lib/types/core/align.d.ts +10 -0
  144. package/lib/types/core/config.d.ts +44 -0
  145. package/lib/types/core/focus.d.ts +24 -0
  146. package/lib/types/core/jump.d.ts +39 -0
  147. package/lib/types/core/logic/active-dot.d.ts +15 -0
  148. package/lib/types/core/logic/focus.d.ts +22 -0
  149. package/lib/types/core/logic/jump.d.ts +39 -0
  150. package/lib/types/core/logic/nodes.d.ts +48 -0
  151. package/lib/types/core/model/nav-item.d.ts +12 -0
  152. package/lib/types/core/model/turns.d.ts +30 -0
  153. package/lib/types/core/nav-item.d.ts +12 -0
  154. package/lib/types/core/nodes.d.ts +43 -0
  155. package/lib/types/core/page-size.d.ts +8 -0
  156. package/lib/types/core/question-entry.d.ts +12 -0
  157. package/lib/types/core/time.d.ts +4 -0
  158. package/lib/types/core/turn-dots.d.ts +29 -0
  159. package/lib/types/core/utils/measure.d.ts +12 -0
  160. package/lib/types/core/utils/time.d.ts +4 -0
  161. package/lib/types/index.d.ts +4 -0
  162. package/lib/types/nav-item.d.ts +12 -0
  163. package/lib/types/nodes.d.ts +48 -0
  164. package/lib/types/projection.d.ts +71 -0
  165. package/lib/types/schema.d.ts +37 -0
  166. package/lib/types/search.d.ts +42 -0
  167. package/lib/types/settings.d.ts +99 -0
  168. package/package.json +71 -0
  169. package/src/client/components/RailDispatch.tsx +27 -0
  170. package/src/client/components/codex/CodexRail.tsx +348 -0
  171. package/src/client/components/deepseek/DeepseekRail.tsx +522 -0
  172. package/src/client/components/minimal/MinimalRail.tsx +324 -0
  173. package/src/client/components/minimal/dot.tsx +32 -0
  174. package/src/client/components/rail/cards.tsx +102 -0
  175. package/src/client/components/rail/hint.tsx +50 -0
  176. package/src/client/components/rail/paging.tsx +26 -0
  177. package/src/client/components/rail/quick-settings.tsx +130 -0
  178. package/src/client/components/rail/search.tsx +147 -0
  179. package/src/client/components/rail/useRail.ts +906 -0
  180. package/src/client/components/settings/SettingsPage.tsx +198 -0
  181. package/src/client/components/settings/StandaloneSettings.tsx +28 -0
  182. package/src/client/components/shared/types.ts +99 -0
  183. package/src/client/index.ts +388 -0
  184. package/src/client/jump.ts +293 -0
  185. package/src/client/locales.ts +143 -0
  186. package/src/client/settings.ts +482 -0
  187. package/src/client/styles.css +1580 -0
  188. package/src/compat.ts +161 -0
  189. package/src/index.ts +66 -0
  190. package/src/projection.ts +174 -0
  191. package/src/search.ts +291 -0
  192. 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
+ }