argo-search 2.15.0 → 2.17.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.
Files changed (183) hide show
  1. package/AGENTS.md +3 -1
  2. package/README.es.md +32 -5
  3. package/README.ja.md +32 -5
  4. package/README.ko.md +32 -5
  5. package/README.md +73 -19
  6. package/README.zh.md +73 -19
  7. package/SKILL.md +7 -7
  8. package/assets/readme/counts.json +1 -1
  9. package/assets/readme/hero.svg +3 -3
  10. package/assets/readme/hero.template.svg +121 -0
  11. package/assets/readme/proof-routes.svg +17 -16
  12. package/backends/domain_profiles.json +222 -24
  13. package/backends/engine_registry.yaml +26 -2
  14. package/backends/env_passthrough.txt +2 -0
  15. package/backends/quota_profiles.json +23 -3
  16. package/bin/argo +3 -0
  17. package/config.yaml +16 -0
  18. package/docs/CHANGELOG.md +31 -0
  19. package/docs/COMMIT_STANDARD.md +10 -0
  20. package/docs/ENGINE_CATALOG.md +40 -37
  21. package/docs/MCP_SETUP.md +9 -0
  22. package/docs/RELEASE_NOTES_v2.16.0.md +58 -0
  23. package/docs/RELEASE_NOTES_v2.17.0.md +64 -0
  24. package/docs/RELEASING.md +1 -1
  25. package/engines/specs/archive_org.yaml +1 -1
  26. package/engines/specs/carbon_intensity.yaml +1 -1
  27. package/engines/specs/crates.yaml +1 -1
  28. package/engines/specs/crossref.yaml +6 -2
  29. package/engines/specs/crt_sh.yaml +1 -1
  30. package/engines/specs/dblp.yaml +1 -1
  31. package/engines/specs/devto.yaml +1 -1
  32. package/engines/specs/docker_hub.yaml +1 -1
  33. package/engines/specs/europepmc.yaml +1 -1
  34. package/engines/specs/fxtwitter.yaml +1 -1
  35. package/engines/specs/gbfs_nyc.yaml +1 -1
  36. package/engines/specs/gleif.yaml +1 -1
  37. package/engines/specs/gov_regulations.yaml +1 -1
  38. package/engines/specs/hackernews.yaml +2 -0
  39. package/engines/specs/helve.yaml +49 -0
  40. package/engines/specs/hf_datasets.yaml +1 -1
  41. package/engines/specs/hf_papers.yaml +2 -0
  42. package/engines/specs/huggingface.yaml +1 -1
  43. package/engines/specs/keenable.yaml +7 -1
  44. package/engines/specs/linux_do.yaml +63 -0
  45. package/engines/specs/local_crossref.yaml +3 -1
  46. package/engines/specs/local_github.yaml +1 -1
  47. package/engines/specs/local_npm.yaml +6 -0
  48. package/engines/specs/local_openstreetmap.yaml +1 -1
  49. package/engines/specs/maven.yaml +1 -1
  50. package/engines/specs/mdn.yaml +1 -1
  51. package/engines/specs/musicbrainz.yaml +1 -1
  52. package/engines/specs/nasa_images.yaml +1 -1
  53. package/engines/specs/nhtsa_vpic.yaml +6 -3
  54. package/engines/specs/npm.yaml +1 -1
  55. package/engines/specs/nuget.yaml +1 -1
  56. package/engines/specs/nvd.yaml +1 -1
  57. package/engines/specs/openalex.yaml +13 -4
  58. package/engines/specs/openreview.yaml +1 -1
  59. package/engines/specs/polymarket.yaml +1 -1
  60. package/engines/specs/sec_edgar.yaml +1 -1
  61. package/engines/specs/steam.yaml +1 -1
  62. package/engines/specs/vam.yaml +1 -1
  63. package/engines/specs/wikidata.yaml +1 -1
  64. package/engines/specs/wikipedia.yaml +1 -1
  65. package/engines/specs/zhihu_hot_app.yaml +1 -1
  66. package/package.json +3 -1
  67. package/packages/dsh-plugin/README.md +5 -2
  68. package/packages/dsh-plugin/cordis.patch.yml +4 -1
  69. package/packages/dsh-plugin/dsh/client.js +69 -74
  70. package/packages/dsh-plugin/dsh/diagnostics.js +25 -4
  71. package/packages/dsh-plugin/dsh/index.js +115 -21
  72. package/packages/dsh-plugin/dsh/route-guard.js +95 -0
  73. package/packages/dsh-plugin/dsh/runner.js +50 -7
  74. package/packages/dsh-plugin/dsh/wide-research.js +20 -18
  75. package/packages/dsh-plugin/dsh/workbench-client.js +895 -0
  76. package/packages/dsh-plugin/dsh/workbench-io.js +163 -0
  77. package/packages/dsh-plugin/dsh/workbench-md.js +386 -0
  78. package/packages/dsh-plugin/dsh/workbench-search.js +385 -0
  79. package/packages/dsh-plugin/dsh/workbench-suggestions.js +460 -0
  80. package/packages/dsh-plugin/dsh/workbench.js +703 -0
  81. package/packages/dsh-plugin/icon.svg +23 -0
  82. package/packages/dsh-plugin/package.json +6 -3
  83. package/packages/dsh-plugin/scripts/sync-local.mjs +4 -2
  84. package/packages/dsh-plugin/scripts/sync-local.sh +4 -2
  85. package/packages/dsh-plugin/test/client.test.js +26 -0
  86. package/packages/dsh-plugin/test/diagnostics.test.js +5 -2
  87. package/packages/dsh-plugin/test/index.test.js +150 -1
  88. package/packages/dsh-plugin/test/workbench-concurrency.test.js +98 -0
  89. package/packages/dsh-plugin/test/workbench.test.js +420 -0
  90. package/scripts/adaptive.py +13 -11
  91. package/scripts/argo_paths.py +2 -2
  92. package/scripts/badcase_ledger.py +9 -0
  93. package/scripts/browser_auth.py +178 -4
  94. package/scripts/cache.py +69 -70
  95. package/scripts/check_commit_report.py +46 -0
  96. package/scripts/chrome_cdp.py +71 -0
  97. package/scripts/circuit_breaker.py +91 -13
  98. package/scripts/config_cache.py +23 -10
  99. package/scripts/daemon.py +14 -2
  100. package/scripts/engine_add.py +45 -0
  101. package/scripts/engine_dispatch.py +32 -49
  102. package/scripts/engine_env.py +13 -4
  103. package/scripts/engine_failure.py +33 -0
  104. package/scripts/engine_fingerprint.py +114 -0
  105. package/scripts/engine_health.py +130 -0
  106. package/scripts/engine_states.py +50 -0
  107. package/scripts/engines_base.py +31 -19
  108. package/scripts/engines_builders_archive.py +4 -3
  109. package/scripts/engines_builders_batch11.py +2 -1
  110. package/scripts/engines_builders_batch13.py +4 -3
  111. package/scripts/engines_builders_batch14.py +2 -1
  112. package/scripts/engines_builders_batch15.py +2 -1
  113. package/scripts/engines_builders_batch9.py +2 -2
  114. package/scripts/engines_builders_cn.py +7 -7
  115. package/scripts/engines_builders_data.py +12 -11
  116. package/scripts/engines_builders_data_macro.py +5 -4
  117. package/scripts/engines_builders_dsh.py +2 -1
  118. package/scripts/engines_builders_feeds.py +34 -19
  119. package/scripts/engines_builders_finance.py +2 -1
  120. package/scripts/engines_builders_intl.py +3 -2
  121. package/scripts/engines_builders_media.py +59 -12
  122. package/scripts/engines_builders_science.py +8 -7
  123. package/scripts/engines_builders_search.py +19 -8
  124. package/scripts/engines_builders_skill.py +2 -1
  125. package/scripts/engines_builders_tech.py +19 -19
  126. package/scripts/engines_builders_weather.py +9 -4
  127. package/scripts/engines_fields.py +23 -0
  128. package/scripts/engines_http.py +50 -1
  129. package/scripts/engines_mcp.py +28 -6
  130. package/scripts/evidence_grounding.py +182 -0
  131. package/scripts/evidence_loop.py +15 -1
  132. package/scripts/extend_route_labels.py +6 -0
  133. package/scripts/fetch_browser.py +25 -10
  134. package/scripts/fetch_jina.py +98 -0
  135. package/scripts/fetch_v3.py +52 -93
  136. package/scripts/gate_manifest_check.py +75 -0
  137. package/scripts/gen_readme_art.py +264 -0
  138. package/scripts/image_vision/vision_probe +0 -0
  139. package/scripts/install.sh +2 -0
  140. package/scripts/matrix_search_eval.py +8 -10
  141. package/scripts/mcp_transport.py +33 -9
  142. package/scripts/numeric_verify.py +12 -2
  143. package/scripts/output_transparency.py +3 -0
  144. package/scripts/pre-commit +57 -8
  145. package/scripts/query_operators.py +229 -1
  146. package/scripts/quota.py +46 -63
  147. package/scripts/recovery.py +19 -16
  148. package/scripts/recovery_runner.py +29 -10
  149. package/scripts/redskill/redskill_engine.py +2 -1
  150. package/scripts/release.py +16 -1
  151. package/scripts/research_gates.py +85 -1
  152. package/scripts/route.py +8 -0
  153. package/scripts/route_combo.py +24 -3
  154. package/scripts/route_policy.py +1 -1
  155. package/scripts/search_attribution.py +20 -0
  156. package/scripts/search_entry.py +27 -0
  157. package/scripts/search_output.py +18 -7
  158. package/scripts/search_pipeline.py +3 -3
  159. package/scripts/semantic_evidence.py +20 -11
  160. package/scripts/serp_guard.py +13 -1
  161. package/scripts/settings_page.py +1 -0
  162. package/scripts/single_flight.py +1 -1
  163. package/scripts/social_engines/hackernews_engine.py +2 -1
  164. package/scripts/social_engines/reddit_engine.py +2 -1
  165. package/scripts/social_engines/zhihu_engine.py +2 -1
  166. package/scripts/source_audit.py +42 -7
  167. package/scripts/source_discovery.py +611 -0
  168. package/scripts/sync_backends.py +45 -0
  169. package/scripts/usage_log.py +24 -9
  170. package/scripts/watch.py +3 -3
  171. package/scripts/zhihu_quota.py +2 -1
  172. package/sub-skills/argo-wide-research/SKILL.md +7 -5
  173. package/sub-skills/ego-search/{SKILL.md → README.md} +24 -47
  174. package/sub-skills/ego-search/scripts/ego_search.py +195 -19
  175. package/sub-skills/ego-search/scripts/pacing.py +291 -0
  176. package/sub-skills/ego-search/scripts/quality.py +262 -6
  177. package/sub-skills/ego-search/scripts/runtime.py +7 -1
  178. package/sub-skills/ego-search/scripts/site_profiles.py +157 -0
  179. package/sub-skills/ego-search/scripts/webbridge_adapter.py +7 -1
  180. package/sub-skills/js-run/{SKILL.md → README.md} +3 -20
  181. package/sub-skills/local-search/{SKILL.md → README.md} +3 -8
  182. package/sub-skills/local-search/engine_registry.py +32 -7
  183. package/sub-skills/local-seek/SKILL.md +20 -22
@@ -0,0 +1,895 @@
1
+ /*
2
+ * @taxueseek/argo-dsh — 搜索分析工作台前端模块(ES Module,零构建依赖)
3
+ *
4
+ * 通过 /argo/workbench-client.js 由 Host 提供,挂载到 DSH:
5
+ * - main slot(key: 'argo-workbench')
6
+ * - sidebar.panellist(id: 'argo-workbench')
7
+ * - 全局划词浮层(选中对话内容一键进入工作台分析)
8
+ */
9
+
10
+ import { CSS, renderMarkdown } from '/argo/workbench-md.js'
11
+
12
+ const STATE_KEY = 'argo-workbench:state.v1'
13
+ const PREFS_KEY = 'argo-workbench:prefs.v1'
14
+ // 每日热点刷新时间选项与默认值(此前两处下拉手抄同一数组,2026-11-20 审计单源化;
15
+ // 默认值须与 workbench-suggestions.js 的 DEFAULT_REFRESH_TIME 保持一致)
16
+ const REFRESH_TIME_OPTIONS = ['07:00', '08:00', '08:30', '09:00', '12:00', '18:00', '20:00', '22:00']
17
+ const DEFAULT_REFRESH_TIME = '08:30'
18
+
19
+ const CORE_MODES = [
20
+ { id: 'general', label: '全网搜索', desc: '多源快查,先给结论再列出处', ph: '搜任何问题、概念、报错或资料(Enter 发送,Shift+Enter 换行)…' },
21
+ { id: 'hotspot', label: '热点分析', desc: '梳理近期事件脉络、争议与各方立场', ph: '输入热点事件、行业动态或争议话题,看多方观点…' },
22
+ { id: 'research', label: '深度研究', desc: '多维拆解、原文核验并生成研究报告', ph: '输入需要系统调研的复杂问题,生成带来源账本的报告…' },
23
+ ]
24
+
25
+ const TOPIC_CARDS = [
26
+ {
27
+ id: 'verify',
28
+ label: '真假核验',
29
+ desc: '抓取原文核对出处,给出可信度判断',
30
+ ph: '输入需要核验真假的传闻、数据或说法…',
31
+ samples: [
32
+ '核验某项公开行业统计数据的原始官方出处',
33
+ '核实近期热门科技传闻的官方公告与时间线',
34
+ '核对某软件开源协议或最新收费政策的官方条款',
35
+ ],
36
+ },
37
+ {
38
+ id: 'compare',
39
+ label: '选型对比',
40
+ desc: '多维度对比产品、方案优缺点与替代',
41
+ ph: '输入要对比的两个或多个产品、工具或方案…',
42
+ samples: [
43
+ '主流本地知识库方案对比:架构、成本与适用场景',
44
+ '常见全文检索与向量数据库选型优缺点对比',
45
+ '主流个人知识管理工具功能与迁移成本对比',
46
+ ],
47
+ },
48
+ {
49
+ id: 'academic',
50
+ label: '学术文献',
51
+ desc: '学术多源深挖,梳理方法与实验结论',
52
+ ph: '输入论文主题、研究方向或具体文献关键词…',
53
+ samples: [
54
+ '推理时计算扩展方法最新研究综述与实验对比',
55
+ '多智能体协作与检索增强生成前沿论文梳理',
56
+ '端侧模型量化与低延迟推理优化技术进展',
57
+ ],
58
+ },
59
+ {
60
+ id: 'plugin',
61
+ label: '插件评测',
62
+ desc: '汇总官方说明、社区口碑与安装注意',
63
+ ph: '输入想评估的工具、扩展或插件类型…',
64
+ samples: [
65
+ '热门效率工具与浏览器扩展的真实口碑与安全评估',
66
+ '常用代码编辑器高星插件生态对比与避坑指南',
67
+ '开源自动化工作流插件的局限性与替代方案',
68
+ ],
69
+ },
70
+ {
71
+ id: 'local',
72
+ label: '本机检索',
73
+ desc: '基于 local-seek 检索本机代码与文档',
74
+ ph: '输入要在本机检索的关键词、符号或文件名…',
75
+ samples: [
76
+ 'circuit_breaker',
77
+ 'engine_states',
78
+ 'wide-research',
79
+ ],
80
+ },
81
+ ]
82
+
83
+ const pickSample = (samples) => samples[Math.floor(Math.random() * samples.length)]
84
+
85
+ const ALL_MODES = [...CORE_MODES, ...TOPIC_CARDS]
86
+
87
+ function injectStyle() {
88
+ if (typeof document === 'undefined') return
89
+ if (document.getElementById('argo-wb-style')) return
90
+ const el = document.createElement('style')
91
+ el.id = 'argo-wb-style'
92
+ el.textContent = CSS
93
+ document.head.appendChild(el)
94
+ }
95
+
96
+ function readStorage(key, fallback) {
97
+ try {
98
+ const raw = window.localStorage.getItem(key)
99
+ return raw ? JSON.parse(raw) : fallback
100
+ } catch {
101
+ return fallback
102
+ }
103
+ }
104
+
105
+ function writeStorage(key, value) {
106
+ try {
107
+ window.localStorage.setItem(key, JSON.stringify(value))
108
+ } catch { /* ignore */ }
109
+ }
110
+
111
+ function formatInterval(mins) {
112
+ if (mins >= 43200) return '每月一次'
113
+ if (mins >= 10080) return '每周一次'
114
+ if (mins >= 1440) return '每日一次'
115
+ return mins >= 60 ? `每 ${Math.round(mins / 60)} 小时` : `每 ${mins} 分钟`
116
+ }
117
+
118
+ function formatTime(iso) {
119
+ if (!iso) return '尚未运行'
120
+ try {
121
+ const d = new Date(iso)
122
+ return `${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')} ${String(d.getHours()).padStart(2, '0')}:${String(d.getMinutes()).padStart(2, '0')}`
123
+ } catch {
124
+ return iso
125
+ }
126
+ }
127
+
128
+ export function mountArgoWorkbench(ctx, react) {
129
+ injectStyle()
130
+ const h = react.createElement
131
+ const { useState, useEffect, useRef } = react
132
+
133
+ let pendingExternal = null
134
+ const listeners = new Set()
135
+
136
+ const requestSearch = (query, mode = 'general') => {
137
+ const clean = String(query || '').trim()
138
+ if (!clean) return false
139
+ pendingExternal = { query: clean, mode }
140
+ for (const fn of listeners) fn(pendingExternal)
141
+ return true
142
+ }
143
+
144
+ const resolveLang = () => {
145
+ const loc = ctx?.locale ?? (typeof ctx?.get === 'function' ? ctx.get('locale') : null)
146
+ const active = loc?.getSnapshot?.()?.active || (typeof navigator !== 'undefined' ? navigator.language : 'zh')
147
+ return String(active).toLowerCase().startsWith('en') ? 'en' : 'zh'
148
+ }
149
+
150
+ function WorkbenchApp() {
151
+ const [initialSaved] = useState(() => readStorage(STATE_KEY, null))
152
+ const [prefs, setPrefs] = useState(() => readStorage(PREFS_KEY, { selection: true }))
153
+ const [lang, setLang] = useState(resolveLang)
154
+ const [view, setView] = useState('home')
155
+ const [input, setInput] = useState('')
156
+ const [activeQuery, setActiveQuery] = useState(() => initialSaved?.query || '')
157
+ const [mode, setMode] = useState('general')
158
+ const [topicSamples, setTopicSamples] = useState(() => Object.fromEntries(TOPIC_CARDS.map(t => [t.id, pickSample(t.samples)])))
159
+ const [suggestions, setSuggestions] = useState([])
160
+ const [hotspotMeta, setHotspotMeta] = useState({ refreshTime: '08:30', lastRefreshedAt: '' })
161
+ const [hotspotBusy, setHotspotBusy] = useState(false)
162
+ const [hotspotNote, setHotspotNote] = useState('')
163
+ const [cards, setCards] = useState(() => initialSaved?.cards || [])
164
+ const [turns, setTurns] = useState(() => initialSaved?.turns || [])
165
+ const [stageText, setStageText] = useState('')
166
+ const [loading, setLoading] = useState(false)
167
+ const [filter, setFilter] = useState('all')
168
+ const [flashId, setFlashId] = useState('')
169
+ const [followup, setFollowup] = useState('')
170
+ const [popover, setPopover] = useState(null) // null | 'debug' | 'settings' | 'watch'
171
+ const [diagItems, setDiagItems] = useState([])
172
+ const [healthInfo, setHealthInfo] = useState(null)
173
+ const [gateResult, setGateResult] = useState(null)
174
+ const [clarifyInfo, setClarifyInfo] = useState(null)
175
+ const [evidenceSummary, setEvidenceSummary] = useState(null)
176
+ const [watches, setWatches] = useState([])
177
+ const [watchQuery, setWatchQuery] = useState('')
178
+ const [watchInterval, setWatchInterval] = useState(1440)
179
+ const [watchBusyId, setWatchBusyId] = useState('')
180
+ const inputRef = useRef(null)
181
+ const esRef = useRef(null)
182
+ const abortRef = useRef(null)
183
+ const modeRef = useRef(mode)
184
+ const startSearchRef = useRef(null)
185
+ const suggestSeqRef = useRef(0)
186
+ modeRef.current = mode
187
+
188
+ useEffect(() => {
189
+ if (loading) return undefined
190
+ const t = setTimeout(() => {
191
+ writeStorage(STATE_KEY, { query: activeQuery, mode, cards, turns })
192
+ }, 400)
193
+ return () => clearTimeout(t)
194
+ }, [activeQuery, mode, cards, turns, loading])
195
+
196
+ const refreshWatches = async () => {
197
+ try {
198
+ const res = await fetch('/argo/api/watches')
199
+ const data = await res.json()
200
+ if (Array.isArray(data.items)) setWatches(data.items)
201
+ } catch { /* ignore */ }
202
+ }
203
+
204
+ const refreshSuggestions = async (targetMode = mode, targetLang = lang, shuffle = false) => {
205
+ const seq = ++suggestSeqRef.current
206
+ try {
207
+ const res = await fetch(`/argo/api/suggestions?mode=${encodeURIComponent(targetMode)}&lang=${encodeURIComponent(targetLang)}&shuffle=${shuffle ? '1' : '0'}`)
208
+ const data = await res.json()
209
+ if (seq === suggestSeqRef.current && Array.isArray(data?.items)) {
210
+ setSuggestions(data.items)
211
+ if (data.meta) setHotspotMeta(prev => ({ ...prev, ...data.meta }))
212
+ }
213
+ } catch { /* ignore */ }
214
+ }
215
+
216
+ useEffect(() => {
217
+ const loc = ctx?.locale ?? (typeof ctx?.get === 'function' ? ctx.get('locale') : null)
218
+ if (!loc?.subscribe) return undefined
219
+ return loc.subscribe(() => setLang(resolveLang()))
220
+ }, [])
221
+
222
+ useEffect(() => {
223
+ refreshSuggestions(mode, lang, false)
224
+ }, [mode, lang])
225
+
226
+ useEffect(() => { refreshWatches() }, [])
227
+
228
+ const startSearch = (qText, targetMode = mode, refresh = false) => {
229
+ const q = String(qText || '').trim()
230
+ if (!q) return
231
+ if (esRef.current) { esRef.current.close(); esRef.current = null }
232
+ if (abortRef.current) { abortRef.current.abort(); abortRef.current = null }
233
+
234
+ setView('result')
235
+ setActiveQuery(q)
236
+ setInput(q)
237
+ setMode(targetMode)
238
+ setCards([])
239
+ setTurns([{ role: 'assistant', text: '' }])
240
+ setStageText('正在连接 Argo 多源检索引擎…')
241
+ setLoading(true)
242
+ setFilter('all')
243
+ setPopover(null)
244
+ setGateResult(null)
245
+ setClarifyInfo(null)
246
+ setEvidenceSummary(null)
247
+
248
+ const url = `/argo/api/stream?q=${encodeURIComponent(q)}&mode=${encodeURIComponent(targetMode)}&refresh=${refresh ? '1' : '0'}`
249
+ const es = new EventSource(url)
250
+ esRef.current = es
251
+
252
+ const parse = (ev) => { try { return JSON.parse(ev.data) } catch { return {} } }
253
+ es.addEventListener('status', (ev) => { const d = parse(ev); if (d.message) setStageText(d.message) })
254
+ es.addEventListener('clarify', (ev) => { const d = parse(ev); if (d && (d.explanation || d.ambiguities?.length)) setClarifyInfo(d) })
255
+ es.addEventListener('evidence', (ev) => { const d = parse(ev); if (d && (d.crossValidation || d.summary)) setEvidenceSummary(d) })
256
+ es.addEventListener('cards', (ev) => { const d = parse(ev); if (Array.isArray(d.cards)) setCards(d.cards) })
257
+ es.addEventListener('gate', (ev) => { const d = parse(ev); if (typeof d.passed === 'boolean') setGateResult(d) })
258
+ es.addEventListener('answer', (ev) => {
259
+ const d = parse(ev)
260
+ if (!d.delta) return
261
+ setTurns(prev => {
262
+ const next = [...prev]
263
+ const last = next[next.length - 1]
264
+ if (last && last.role === 'assistant') next[next.length - 1] = { ...last, text: last.text + d.delta }
265
+ return next
266
+ })
267
+ })
268
+ es.addEventListener('answer-status', (ev) => { const d = parse(ev); if (d.message) setStageText(d.message) })
269
+ es.addEventListener('done', () => { setLoading(false); setStageText(''); es.close(); esRef.current = null })
270
+ es.addEventListener('failure', (ev) => { const d = parse(ev); setLoading(false); setStageText(`检索出错:${d.message || '未知错误'}`); es.close(); esRef.current = null })
271
+ es.onerror = () => {
272
+ es.close()
273
+ if (esRef.current === es) esRef.current = null
274
+ setLoading(false)
275
+ }
276
+ }
277
+ startSearchRef.current = startSearch
278
+
279
+ useEffect(() => {
280
+ const handler = (req) => {
281
+ if (!req) return
282
+ pendingExternal = null
283
+ startSearchRef.current?.(req.query, req.mode || modeRef.current)
284
+ }
285
+ listeners.add(handler)
286
+ if (pendingExternal) handler(pendingExternal)
287
+ return () => {
288
+ listeners.delete(handler)
289
+ if (esRef.current) esRef.current.close()
290
+ if (abortRef.current) abortRef.current.abort()
291
+ }
292
+ }, [])
293
+
294
+ const handleFollowup = async (e) => {
295
+ e.preventDefault()
296
+ const q = followup.trim()
297
+ if (!q || loading) return
298
+ setFollowup('')
299
+ setLoading(true)
300
+ setStageText('正在结合当前证据回答追问…')
301
+
302
+ const historySnapshot = [...turns]
303
+ setTurns(prev => [...prev, { role: 'user', text: q }, { role: 'assistant', text: '' }])
304
+
305
+ const ac = new AbortController()
306
+ abortRef.current = ac
307
+ try {
308
+ const res = await fetch('/argo/api/followup', {
309
+ method: 'POST',
310
+ headers: { 'Content-Type': 'application/json' },
311
+ body: JSON.stringify({ query: activeQuery, mode, cards, history: historySnapshot, question: q }),
312
+ signal: ac.signal,
313
+ })
314
+ if (!res.ok || !res.body) {
315
+ setStageText(`追问失败(HTTP ${res.status})`)
316
+ return
317
+ }
318
+ const reader = res.body.getReader()
319
+ const dec = new TextDecoder()
320
+ let buf = ''
321
+ while (true) {
322
+ const { value, done } = await reader.read()
323
+ if (done) break
324
+ buf += dec.decode(value, { stream: true })
325
+ const parts = buf.split('\n\n')
326
+ buf = parts.pop() || ''
327
+ for (const chunk of parts) {
328
+ const evMatch = chunk.match(/^event:\s*(.+)$/m)
329
+ const dataMatch = chunk.match(/^data:\s*(.+)$/m)
330
+ if (!dataMatch) continue
331
+ const evName = evMatch ? evMatch[1].trim() : 'message'
332
+ let payload
333
+ try { payload = JSON.parse(dataMatch[1]) } catch { continue }
334
+ if (evName === 'answer' && payload.delta) {
335
+ setTurns(prev => {
336
+ const next = [...prev]
337
+ const last = next[next.length - 1]
338
+ if (last && last.role === 'assistant') next[next.length - 1] = { ...last, text: last.text + payload.delta }
339
+ return next
340
+ })
341
+ } else if (evName === 'failure' && payload.message) {
342
+ setStageText(`追问出错:${payload.message}`)
343
+ }
344
+ }
345
+ }
346
+ } catch { /* ignore */ } finally {
347
+ setLoading(false)
348
+ setStageText('')
349
+ abortRef.current = null
350
+ }
351
+ }
352
+
353
+ const createWatch = async (qStr, targetMode = mode, mins = watchInterval) => {
354
+ const q = String(qStr || '').trim()
355
+ if (!q) return
356
+ try {
357
+ const res = await fetch('/argo/api/watches', {
358
+ method: 'POST',
359
+ headers: { 'Content-Type': 'application/json' },
360
+ body: JSON.stringify({ query: q, mode: targetMode, intervalMinutes: mins }),
361
+ })
362
+ const data = await res.json()
363
+ if (Array.isArray(data.items)) setWatches(data.items)
364
+ setWatchQuery('')
365
+ setPopover('watch') // 抽屉可见性由 popover 状态管(此前引用未定义的 setWatchOpen)
366
+ } catch { /* ignore */ }
367
+ }
368
+
369
+ const runWatchNow = async (id) => {
370
+ setWatchBusyId(id)
371
+ try {
372
+ const res = await fetch('/argo/api/watches/run', {
373
+ method: 'POST',
374
+ headers: { 'Content-Type': 'application/json' },
375
+ body: JSON.stringify({ id }),
376
+ })
377
+ const data = await res.json()
378
+ if (Array.isArray(data.items)) setWatches(data.items)
379
+ } finally {
380
+ setWatchBusyId('')
381
+ }
382
+ }
383
+
384
+ const deleteWatch = async (id) => {
385
+ try {
386
+ const res = await fetch(`/argo/api/watches?id=${encodeURIComponent(id)}`, { method: 'DELETE' })
387
+ const data = await res.json()
388
+ if (Array.isArray(data.items)) setWatches(data.items)
389
+ } catch { /* ignore */ }
390
+ }
391
+
392
+ const openWatchResult = (w) => {
393
+ setView('result')
394
+ setActiveQuery(w.query)
395
+ setInput(w.query)
396
+ setMode(w.mode || 'general')
397
+ setCards(Array.isArray(w.lastCards) ? w.lastCards : [])
398
+ setTurns([{ role: 'assistant', text: w.lastSummary || '该定时任务尚未生成摘要,可点击「立即执行」或「强制刷新」。' }])
399
+ setPopover(null)
400
+ }
401
+
402
+ const scrollToCard = (cardId) => {
403
+ const el = document.getElementById(`aw-${cardId}`)
404
+ if (el) {
405
+ el.scrollIntoView({ behavior: 'smooth', block: 'center' })
406
+ setFlashId(cardId)
407
+ setTimeout(() => setFlashId(''), 1400)
408
+ }
409
+ }
410
+
411
+ const refreshHealth = async () => {
412
+ try {
413
+ const res = await fetch('/argo/api/health')
414
+ const data = await res.json()
415
+ if (data?.ok) setHealthInfo(data)
416
+ } catch { /* ignore */ }
417
+ }
418
+
419
+ const openDebug = async () => {
420
+ const next = popover === 'debug' ? null : 'debug'
421
+ setPopover(next)
422
+ if (next === 'debug') {
423
+ refreshHealth()
424
+ try {
425
+ const res = await fetch('/argo/api/diagnostics')
426
+ const data = await res.json()
427
+ setDiagItems(data.items || [])
428
+ } catch { /* ignore */ }
429
+ }
430
+ }
431
+
432
+ const toggleWatchPanel = () => {
433
+ const next = popover === 'watch' ? null : 'watch'
434
+ setPopover(next)
435
+ if (next === 'watch') refreshWatches()
436
+ }
437
+
438
+ const toggleSettingsPanel = () => {
439
+ const next = popover === 'settings' ? null : 'settings'
440
+ setPopover(next)
441
+ if (next === 'settings') refreshHealth()
442
+ }
443
+
444
+ const updateHotspotRefreshTime = async (refreshTime) => {
445
+ setHotspotMeta(prev => ({ ...prev, refreshTime }))
446
+ try {
447
+ const res = await fetch('/argo/api/suggestions/config', {
448
+ method: 'POST',
449
+ headers: { 'Content-Type': 'application/json' },
450
+ body: JSON.stringify({ refreshTime }),
451
+ })
452
+ const data = await res.json()
453
+ if (data?.ok) {
454
+ const sched = { refreshTime: data.refreshTime, lastRefreshedAt: data.lastRefreshedAt }
455
+ setHotspotMeta(sched)
456
+ setHealthInfo(prev => ({ ...(prev || {}), hotspotSchedule: sched }))
457
+ }
458
+ } catch { /* ignore */ }
459
+ }
460
+
461
+ const refreshHotspotsNow = async () => {
462
+ if (hotspotBusy) return
463
+ setHotspotBusy(true)
464
+ try {
465
+ const res = await fetch('/argo/api/suggestions/config', {
466
+ method: 'POST',
467
+ headers: { 'Content-Type': 'application/json' },
468
+ body: JSON.stringify({ refreshNow: true }),
469
+ })
470
+ const data = await res.json()
471
+ if (data?.skipped === 'lock_busy') {
472
+ // 锁被另一宿主占着:如实提示,不拿旧 lastRefreshedAt 冒充刚刷过
473
+ setHotspotNote(lang === 'en' ? 'Another host is refreshing…' : '另一宿主刷新中…')
474
+ window.setTimeout(() => setHotspotNote(''), 8000)
475
+ } else if (data?.ok) {
476
+ setHotspotNote('')
477
+ const sched = { refreshTime: data.refreshTime, lastRefreshedAt: data.lastRefreshedAt }
478
+ setHotspotMeta(sched)
479
+ setHealthInfo(prev => ({ ...(prev || {}), hotspotSchedule: sched }))
480
+ }
481
+ await refreshSuggestions(modeRef.current, lang, false)
482
+ } catch { /* ignore */ } finally {
483
+ setHotspotBusy(false)
484
+ }
485
+ }
486
+
487
+ const toggleEgoSearch = async () => {
488
+ const current = Boolean(healthInfo?.egoSearch?.enabled)
489
+ try {
490
+ const res = await fetch('/argo/api/ego-search', {
491
+ method: 'POST',
492
+ headers: { 'Content-Type': 'application/json' },
493
+ body: JSON.stringify({ enabled: !current }),
494
+ })
495
+ const data = await res.json()
496
+ if (data?.ok) setHealthInfo(prev => ({ ...(prev || {}), egoSearch: data.egoSearch }))
497
+ } catch { /* ignore */ }
498
+ }
499
+
500
+ const toggleSelectionPref = () => {
501
+ const next = { ...prefs, selection: !prefs.selection }
502
+ setPrefs(next)
503
+ writeStorage(PREFS_KEY, next)
504
+ }
505
+
506
+ const currentModeObj = ALL_MODES.find(m => m.id === mode) || CORE_MODES[0]
507
+ const lockedTopic = TOPIC_CARDS.find(t => t.id === mode) || null
508
+ const verifiedCount = cards.filter(c => c.verified).length
509
+ const visibleCards = filter === 'verified'
510
+ ? cards.filter(c => c.verified)
511
+ : (filter === 'all' ? cards : cards.filter(c => c.source === filter))
512
+ const sources = [...new Set(cards.map(c => c.source))]
513
+
514
+ const renderWatchDrawer = () => popover !== 'watch' ? null : h('div', { className: 'aw-popover' },
515
+ h('div', { style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: '10px' } },
516
+ h('strong', null, '定时搜索与追踪'),
517
+ h('button', { type: 'button', className: 'aw-filter', onClick: () => setPopover(null) }, '关闭')),
518
+ h('form', {
519
+ style: { display: 'flex', gap: '6px', marginBottom: '10px' },
520
+ onSubmit: (e) => { e.preventDefault(); createWatch(watchQuery || activeQuery || input, mode, watchInterval) },
521
+ },
522
+ h('input', {
523
+ className: 'aw-top-input',
524
+ style: { border: '1px solid var(--aw-border)', borderRadius: '8px', padding: '5px 8px', background: 'var(--aw-sunken)' },
525
+ placeholder: '输入定时追踪关键词…',
526
+ value: watchQuery,
527
+ onChange: (e) => setWatchQuery(e.target.value),
528
+ }),
529
+ h('select', {
530
+ className: 'aw-select',
531
+ style: { height: '28px' },
532
+ value: watchInterval,
533
+ onChange: (e) => setWatchInterval(Number(e.target.value)),
534
+ },
535
+ h('option', { value: 1440 }, '每日一次'),
536
+ h('option', { value: 10080 }, '每周一次'),
537
+ h('option', { value: 43200 }, '每月一次')),
538
+ h('button', { type: 'submit', className: 'aw-filter active' }, '添加')),
539
+ watches.length === 0
540
+ ? h('div', { style: { color: 'var(--aw-text-3)', padding: '8px 0' } }, '暂无定时搜索任务')
541
+ : watches.map(w => h('div', { key: w.id, className: 'aw-watch-row' },
542
+ h('div', { style: { fontWeight: 600 } }, `[${w.modeLabel || w.mode}] ${w.query}`),
543
+ h('div', { style: { color: 'var(--aw-text-3)' } }, `${formatInterval(w.intervalMinutes)} · 上次:${formatTime(w.lastRunAt)} · 来源 ${w.lastCardCount || 0}`),
544
+ h('div', { className: 'aw-watch-actions' },
545
+ w.lastSummary ? h('button', { type: 'button', className: 'aw-filter active', onClick: () => openWatchResult(w) }, '查看结果') : null,
546
+ h('button', {
547
+ type: 'button',
548
+ className: 'aw-filter',
549
+ disabled: watchBusyId === w.id,
550
+ onClick: () => runWatchNow(w.id),
551
+ }, watchBusyId === w.id ? '执行中…' : '立即执行'),
552
+ h('button', { type: 'button', className: 'aw-filter', onClick: () => deleteWatch(w.id) }, '删除')))))
553
+
554
+ if (view === 'home') {
555
+ return h('div', { className: 'aw-root' },
556
+ h('div', { className: 'aw-hero' },
557
+ h('div', { className: 'aw-hero-top', style: { gap: '8px' } },
558
+ h('label', { style: { display: 'inline-flex', alignItems: 'center', gap: '5px', fontSize: '12px', color: 'var(--aw-text-2)' } },
559
+ h('span', null, lang === 'en' ? 'Daily refresh' : '每日热点'),
560
+ h('select', {
561
+ value: hotspotMeta.refreshTime || DEFAULT_REFRESH_TIME,
562
+ onChange: (e) => updateHotspotRefreshTime(e.target.value),
563
+ style: { fontSize: '12px', padding: '2px 6px', borderRadius: '6px', border: '1px solid var(--aw-border)', background: 'var(--aw-sunken)', color: 'inherit' },
564
+ }, REFRESH_TIME_OPTIONS.map(t => h('option', { key: t, value: t }, t)))),
565
+ h('button', {
566
+ type: 'button',
567
+ className: 'aw-icon-btn',
568
+ disabled: hotspotBusy,
569
+ onClick: refreshHotspotsNow,
570
+ }, hotspotBusy
571
+ ? (lang === 'en' ? 'Refreshing…' : '刷新中…')
572
+ : (hotspotNote || (lang === 'en' ? 'Refresh Hotspots' : '刷新热点'))),
573
+ h('button', { type: 'button', className: 'aw-icon-btn', onClick: toggleWatchPanel }, `定时搜索 (${watches.length})`)),
574
+ renderWatchDrawer(),
575
+ h('div', { className: 'aw-hero-inner' },
576
+ h('h1', { className: 'aw-slogan' }, lang === 'en' ? 'Search Wide, Verify Fast' : '搜得到,查得快'),
577
+ h('p', { className: 'aw-sub' }, lang === 'en' ? 'Multi-source search, hotspot brief, deep research & scheduled watch' : '全网搜索,热点分析,深度研究,定时搜索'),
578
+ h('form', {
579
+ className: 'aw-box',
580
+ onSubmit: (e) => { e.preventDefault(); startSearch(input, mode) },
581
+ },
582
+ h('textarea', {
583
+ ref: inputRef,
584
+ className: 'aw-textarea',
585
+ placeholder: currentModeObj.ph,
586
+ value: input,
587
+ onChange: (e) => setInput(e.target.value),
588
+ onKeyDown: (e) => {
589
+ if (e.key === 'Enter' && !e.shiftKey) {
590
+ e.preventDefault()
591
+ startSearch(input, mode)
592
+ }
593
+ },
594
+ }),
595
+ h('div', { className: 'aw-box-foot' },
596
+ h('div', { className: 'aw-modes' },
597
+ CORE_MODES.map(m => h('button', {
598
+ key: m.id,
599
+ type: 'button',
600
+ title: m.desc,
601
+ className: `aw-mode-btn ${mode === m.id ? 'active' : ''}`,
602
+ onClick: () => setMode(m.id),
603
+ }, m.label)),
604
+ lockedTopic ? h('span', { className: 'aw-topic-chip' },
605
+ `${lang === 'en' ? 'Topic' : '主题'}:${lockedTopic.label}`,
606
+ h('button', { type: 'button', title: '取消特定主题', onClick: () => setMode('general') }, '×')) : null),
607
+ h('button', {
608
+ type: 'submit',
609
+ className: 'aw-send',
610
+ disabled: !input.trim(),
611
+ title: '开始检索分析',
612
+ }, '→'))),
613
+ suggestions.length > 0 ? h('div', { style: { display: 'flex', flexWrap: 'wrap', gap: '8px', marginTop: '14px', alignItems: 'center' } },
614
+ suggestions.map((s, idx) => h('button', {
615
+ key: `${s.source}-${idx}`,
616
+ type: 'button',
617
+ className: 'aw-filter',
618
+ style: { display: 'inline-flex', alignItems: 'center', gap: '5px', fontSize: '12px', maxWidth: '100%' },
619
+ onClick: () => startSearch(s.query, mode),
620
+ },
621
+ h('span', { style: { opacity: 0.7, fontSize: '11px' } }, `[${s.tag}]`),
622
+ h('span', { style: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', maxWidth: '240px' } }, s.query))),
623
+ h('button', {
624
+ type: 'button',
625
+ className: 'aw-preset-try',
626
+ style: { color: 'var(--aw-text-3)', marginLeft: 'auto' },
627
+ onClick: () => refreshSuggestions(mode, lang, true),
628
+ }, lang === 'en' ? 'Shuffle' : '换一批')) : null,
629
+ h('div', { className: 'aw-sec-head' },
630
+ h('span', null, '特定主题'),
631
+ h('div', { style: { display: 'flex', gap: '10px', alignItems: 'center' } },
632
+ activeQuery && cards.length > 0 ? h('button', {
633
+ type: 'button',
634
+ className: 'aw-preset-try',
635
+ onClick: () => setView('result'),
636
+ }, `继续上次:${activeQuery.slice(0, 14)}${activeQuery.length > 14 ? '…' : ''} ↗`) : null,
637
+ h('button', {
638
+ type: 'button',
639
+ className: 'aw-preset-try',
640
+ style: { color: 'var(--aw-text-3)' },
641
+ onClick: () => setTopicSamples(Object.fromEntries(TOPIC_CARDS.map(t => [t.id, pickSample(t.samples)]))),
642
+ }, '换一批引导'))),
643
+ h('div', { className: 'aw-presets' },
644
+ TOPIC_CARDS.map(item => h('div', {
645
+ key: item.id,
646
+ className: `aw-preset ${mode === item.id ? 'selected' : ''}`,
647
+ onClick: () => { setMode(item.id); inputRef.current?.focus?.() },
648
+ },
649
+ h('div', null,
650
+ h('div', { className: 'aw-preset-tag' }, item.label),
651
+ h('div', { className: 'aw-preset-desc', style: { marginTop: '4px' } }, item.desc)),
652
+ h('button', {
653
+ type: 'button',
654
+ className: 'aw-preset-try',
655
+ onClick: (e) => { e.stopPropagation(); startSearch(topicSamples[item.id] || pickSample(item.samples), item.id) },
656
+ }, '试一试 ↗')))))))
657
+ }
658
+
659
+ return h('div', { className: 'aw-root' },
660
+ h('div', { className: 'aw-topbar' },
661
+ h('button', { type: 'button', className: 'aw-icon-btn', onClick: () => setView('home') }, '← 首页'),
662
+ h('select', {
663
+ className: 'aw-select',
664
+ value: mode,
665
+ onChange: (e) => {
666
+ const nextMode = e.target.value
667
+ setMode(nextMode)
668
+ if (activeQuery) startSearch(activeQuery, nextMode)
669
+ },
670
+ }, ALL_MODES.map(m => h('option', { key: m.id, value: m.id }, m.label))),
671
+ h('form', {
672
+ className: 'aw-top-form',
673
+ onSubmit: (e) => { e.preventDefault(); startSearch(input, mode) },
674
+ },
675
+ h('input', {
676
+ className: 'aw-top-input',
677
+ value: input,
678
+ onChange: (e) => setInput(e.target.value),
679
+ placeholder: '输入新的查询…',
680
+ }),
681
+ h('button', {
682
+ type: 'button',
683
+ className: 'aw-filter',
684
+ title: '跳过缓存重新检索',
685
+ onClick: () => startSearch(input || activeQuery, mode, true),
686
+ }, '强制刷新'),
687
+ h('button', {
688
+ type: 'submit',
689
+ className: 'aw-send',
690
+ style: { width: '28px', height: '28px' },
691
+ disabled: !input.trim(),
692
+ }, '→')),
693
+ h('div', { className: 'aw-stat-pill' }, `${cards.length} 条来源,${verifiedCount} 条已核验`),
694
+ h('button', {
695
+ type: 'button',
696
+ className: 'aw-icon-btn',
697
+ title: '把当前查询加入定时追踪',
698
+ onClick: () => createWatch(activeQuery, mode, watchInterval),
699
+ }, '定时追踪'),
700
+ h('button', { type: 'button', className: 'aw-icon-btn', onClick: toggleWatchPanel }, `定时 (${watches.length})`),
701
+ h('button', { type: 'button', className: 'aw-icon-btn', onClick: openDebug }, 'DEBUG'),
702
+ h('button', {
703
+ type: 'button',
704
+ className: 'aw-icon-btn',
705
+ onClick: toggleSettingsPanel,
706
+ }, '设置')),
707
+
708
+ renderWatchDrawer(),
709
+
710
+ popover === 'debug' ? h('div', { className: 'aw-popover' },
711
+ h('div', { style: { fontWeight: 600, marginBottom: '8px' } }, '最近 20 次工作台检索诊断'),
712
+ healthInfo?.breaker ? h('div', { style: { padding: '6px 8px', marginBottom: '8px', borderRadius: '8px', background: 'var(--aw-sunken)', fontSize: '12px' } },
713
+ `熔断器:${healthInfo.breaker.total} 源 · 非闭合 ${healthInfo.breaker.nonClosedCount} 源` +
714
+ (healthInfo.breaker.topTripped?.length ? `(${healthInfo.breaker.topTripped.slice(0, 3).map(t => `${t.engine}:${t.state}`).join(', ')})` : '')) : null,
715
+ diagItems.length === 0
716
+ ? h('div', { style: { color: 'var(--aw-text-3)' } }, '暂无记录')
717
+ : diagItems.map((it, idx) => h('div', {
718
+ key: idx,
719
+ style: { padding: '6px 0', borderBottom: '1px solid var(--aw-border)' },
720
+ },
721
+ h('div', { style: { fontWeight: 600 } }, `[${it.mode}] ${it.query}`),
722
+ h('div', { style: { color: 'var(--aw-text-3)' } }, `${it.durationMs}ms · 来源 ${it.cardCount} · 核验 ${it.verifiedCount ?? 0} · ${it.status}`)))) : null,
723
+
724
+ popover === 'settings' ? h('div', { className: 'aw-popover', style: { width: '280px' } },
725
+ h('div', { style: { fontWeight: 600, marginBottom: '10px' } }, '工作台偏好与能力'),
726
+ h('label', { style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', cursor: 'pointer', marginBottom: '8px' } },
727
+ h('span', null, '对话划词浮层(Argo 分析)'),
728
+ h('input', { type: 'checkbox', checked: Boolean(prefs.selection), onChange: toggleSelectionPref })),
729
+ h('label', { style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', cursor: 'pointer', marginBottom: '8px' } },
730
+ h('span', null, '登录态专业搜索(ego-search)'),
731
+ h('input', { type: 'checkbox', checked: Boolean(healthInfo?.egoSearch?.enabled), onChange: toggleEgoSearch })),
732
+ h('div', { style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: '8px', marginTop: '8px' } },
733
+ h('span', null, '每日热点更新'),
734
+ h('div', { style: { display: 'flex', alignItems: 'center', gap: '6px' } },
735
+ h('select', {
736
+ value: hotspotMeta.refreshTime || healthInfo?.hotspotSchedule?.refreshTime || DEFAULT_REFRESH_TIME,
737
+ onChange: (e) => updateHotspotRefreshTime(e.target.value),
738
+ style: { fontSize: '12px', padding: '2px 6px', borderRadius: '6px', border: '1px solid var(--aw-border)', background: 'var(--aw-sunken)', color: 'inherit' },
739
+ }, REFRESH_TIME_OPTIONS.map(t => h('option', { key: t, value: t }, t))),
740
+ h('button', { type: 'button', className: 'aw-pill-btn', disabled: hotspotBusy, onClick: refreshHotspotsNow, style: { fontSize: '11px', padding: '2px 8px' } }, hotspotBusy ? '刷新中…' : (hotspotNote || '刷新')))),
741
+ h('button', {
742
+ type: 'button',
743
+ className: 'aw-icon-btn',
744
+ style: { marginTop: '12px', width: '100%', justifyContent: 'center' },
745
+ onClick: () => {
746
+ window.localStorage.removeItem(STATE_KEY)
747
+ setActiveQuery(''); setCards([]); setTurns([]); setGateResult(null); setView('home'); setPopover(null)
748
+ },
749
+ }, '清空当前工作台记录')) : null,
750
+
751
+ h('div', { className: 'aw-main' },
752
+ h('div', null,
753
+ h('div', { className: 'aw-q-head' },
754
+ h('h2', { className: 'aw-q-title' }, activeQuery),
755
+ h('span', { className: 'aw-badge' }, currentModeObj.label),
756
+ evidenceSummary?.crossValidation ? h('span', {
757
+ className: 'aw-badge',
758
+ title: evidenceSummary.crossValidation.detail || '',
759
+ }, `交叉验证:${evidenceSummary.crossValidation.corroboration_level || 'unknown'}${evidenceSummary.summary ? ` · 高可信 ${evidenceSummary.summary.high_credibility || 0}` : ''}`) : null,
760
+ gateResult ? h('span', {
761
+ className: 'aw-badge',
762
+ title: (gateResult.warnings || []).map(w => (typeof w === 'string' ? w : (w?.detail || w?.id || ''))).filter(Boolean).join(';'),
763
+ style: { background: gateResult.passed ? 'var(--aw-sunken)' : '#fef2f2', color: gateResult.passed ? 'var(--aw-text-2)' : '#b91c1c' },
764
+ }, gateResult.passed ? '质量门禁通过' : '质量门禁未达标') : null),
765
+ clarifyInfo ? h('div', { style: { fontSize: '12px', color: 'var(--aw-text-2)', padding: '6px 10px', marginBottom: '10px', borderRadius: '8px', background: 'var(--aw-sunken)' } },
766
+ clarifyInfo.explanation || '',
767
+ Array.isArray(clarifyInfo.ambiguities) && clarifyInfo.ambiguities.length > 0
768
+ ? ` · 歧义提示:${clarifyInfo.ambiguities.slice(0, 2).map(a => a.term || a).join(' / ')}`
769
+ : '') : null,
770
+ loading || stageText ? h('div', { className: 'aw-progress' },
771
+ loading ? h('span', { className: 'aw-dot' }) : null,
772
+ h('span', null, stageText || '处理中…')) : null,
773
+ turns.map((turn, idx) => h('div', { key: idx, className: 'aw-turn' },
774
+ turn.role === 'user'
775
+ ? h('div', { className: 'aw-turn-q' }, turn.text)
776
+ : h('div', { className: 'aw-md' }, renderMarkdown(h, turn.text, cards, scrollToCard)))),
777
+ !loading && cards.length > 0 ? h('form', { className: 'aw-followup', onSubmit: handleFollowup },
778
+ h('input', {
779
+ value: followup,
780
+ onChange: (e) => setFollowup(e.target.value),
781
+ placeholder: '基于当前检索证据继续追问细节…',
782
+ }),
783
+ h('button', { type: 'submit', className: 'aw-send', disabled: !followup.trim() }, '→')) : null),
784
+
785
+ h('div', null,
786
+ h('div', { className: 'aw-right-head' },
787
+ h('strong', { style: { fontSize: '13px' } }, '证据与原文出处'),
788
+ h('div', { className: 'aw-filters' },
789
+ h('button', {
790
+ type: 'button',
791
+ className: `aw-filter ${filter === 'all' ? 'active' : ''}`,
792
+ onClick: () => setFilter('all'),
793
+ }, `全部 (${cards.length})`),
794
+ verifiedCount > 0 ? h('button', {
795
+ type: 'button',
796
+ className: `aw-filter ${filter === 'verified' ? 'active' : ''}`,
797
+ onClick: () => setFilter('verified'),
798
+ }, `已核验 (${verifiedCount})`) : null,
799
+ sources.slice(0, 4).map(src => h('button', {
800
+ key: src,
801
+ type: 'button',
802
+ className: `aw-filter ${filter === src ? 'active' : ''}`,
803
+ onClick: () => setFilter(src),
804
+ }, src)))),
805
+ h('div', { className: 'aw-cards' },
806
+ visibleCards.length === 0
807
+ ? h('div', { style: { color: 'var(--aw-text-3)', fontSize: '13px', padding: '12px' } }, loading ? '正在拉取多源证据…' : '暂无匹配卡片')
808
+ : visibleCards.map(c => h('div', {
809
+ key: c.id,
810
+ id: `aw-${c.id}`,
811
+ className: `aw-card ${flashId === c.id ? 'flash' : ''}`,
812
+ },
813
+ h('div', { className: 'aw-card-top' },
814
+ h('span', { className: 'aw-card-src' },
815
+ h('span', { className: 'aw-idx' }, String(c.index)),
816
+ h('span', null, `${c.source}${c.domain ? ` · ${c.domain}` : ''}`)),
817
+ c.verified ? h('span', { className: 'aw-verified' }, '已核验原文') : null),
818
+ h('p', { className: 'aw-card-quote' }, (c.verifiedText || c.snippet || '暂无摘录').slice(0, 220)),
819
+ h('a', {
820
+ className: 'aw-card-link',
821
+ href: c.url,
822
+ target: '_blank',
823
+ rel: 'noopener noreferrer',
824
+ },
825
+ h('span', { style: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, c.title),
826
+ h('span', { style: { flexShrink: 0 } }, '↗'))))))))
827
+ }
828
+
829
+ function SelectionPill() {
830
+ const [hit, setHit] = useState(null)
831
+
832
+ useEffect(() => {
833
+ let timerId = null
834
+ const checkSelection = () => {
835
+ const prefs = readStorage(PREFS_KEY, { selection: true })
836
+ if (!prefs.selection) { setHit(null); return }
837
+ const sel = window.getSelection?.()
838
+ const text = sel ? String(sel.toString() || '').trim() : ''
839
+ if (text.length < 4 || text.length > 200) { setHit(null); return }
840
+ const range = sel.rangeCount > 0 ? sel.getRangeAt(0) : null
841
+ if (!range) { setHit(null); return }
842
+ const rect = range.getBoundingClientRect()
843
+ if (!rect || (rect.width === 0 && rect.height === 0)) { setHit(null); return }
844
+ setHit({ text, top: Math.max(12, rect.top - 38), left: Math.min(window.innerWidth - 130, Math.max(12, rect.left)) })
845
+ }
846
+ const onUp = () => {
847
+ if (timerId) clearTimeout(timerId)
848
+ timerId = setTimeout(checkSelection, 20)
849
+ }
850
+ document.addEventListener('mouseup', onUp)
851
+ document.addEventListener('keyup', onUp)
852
+ return () => {
853
+ if (timerId) clearTimeout(timerId)
854
+ document.removeEventListener('mouseup', onUp)
855
+ document.removeEventListener('keyup', onUp)
856
+ }
857
+ }, [])
858
+
859
+ if (!hit) return null
860
+ return h('button', {
861
+ type: 'button',
862
+ className: 'aw-sel-pill',
863
+ style: { top: `${hit.top}px`, left: `${hit.left}px` },
864
+ onMouseDown: (e) => {
865
+ e.preventDefault()
866
+ const text = hit.text
867
+ setHit(null)
868
+ requestSearch(text, 'general')
869
+ try {
870
+ ctx.get?.('layout')?.selectPanel?.('argo-workbench')
871
+ } catch { /* ignore */ }
872
+ },
873
+ }, 'Argo 分析')
874
+ }
875
+
876
+ const offs = [
877
+ ctx.slots.inject('main', () => ctx.slots.register({ name: 'main', key: 'argo-workbench' }, WorkbenchApp)),
878
+ ctx.slots.inject('sidebar.panellist', () => ctx.slots.register(
879
+ { name: 'sidebar.panellist', id: 'argo-workbench', order: 5, label: 'Argo 搜索' },
880
+ ({ size = 20, active }) => h('svg', {
881
+ width: size, height: size, viewBox: '0 0 24 24', fill: 'none',
882
+ stroke: active ? '#ea580c' : 'currentColor', strokeWidth: 1.8,
883
+ strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': true,
884
+ },
885
+ h('circle', { cx: 11, cy: 11, r: 7 }),
886
+ h('path', { d: 'M16.5 16.5 21 21' }),
887
+ h('path', { d: 'M11 7.2 13.8 13.8 11 12.3 8.2 13.8 11 7.2Z', fill: '#ea580c', stroke: 'none' })),
888
+ )),
889
+ ctx.slots.inject('global', () => ctx.slots.register({ name: 'global', key: 'argo-workbench-pill' }, SelectionPill)),
890
+ ]
891
+
892
+ return () => {
893
+ for (const off of offs) if (typeof off === 'function') off()
894
+ }
895
+ }