argo-search 2.16.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.
- package/AGENTS.md +3 -1
- package/README.es.md +9 -4
- package/README.ja.md +9 -4
- package/README.ko.md +9 -4
- package/README.md +9 -4
- package/README.zh.md +9 -4
- package/SKILL.md +1 -1
- package/assets/readme/counts.json +1 -1
- package/assets/readme/hero.svg +3 -3
- package/assets/readme/hero.template.svg +121 -0
- package/assets/readme/proof-routes.svg +17 -16
- package/backends/domain_profiles.json +115 -18
- package/backends/engine_registry.yaml +11 -0
- package/backends/env_passthrough.txt +2 -0
- package/backends/quota_profiles.json +10 -0
- package/docs/CHANGELOG.md +17 -1
- package/docs/COMMIT_STANDARD.md +10 -0
- package/docs/ENGINE_CATALOG.md +32 -30
- package/docs/RELEASE_NOTES_v2.17.0.md +64 -0
- package/docs/RELEASING.md +1 -1
- package/engines/specs/crossref.yaml +2 -0
- package/engines/specs/hackernews.yaml +2 -0
- package/engines/specs/helve.yaml +49 -0
- package/engines/specs/hf_papers.yaml +2 -0
- package/engines/specs/openalex.yaml +9 -2
- package/package.json +2 -1
- package/packages/dsh-plugin/README.md +5 -2
- package/packages/dsh-plugin/cordis.patch.yml +4 -1
- package/packages/dsh-plugin/dsh/client.js +57 -63
- package/packages/dsh-plugin/dsh/diagnostics.js +25 -4
- package/packages/dsh-plugin/dsh/index.js +109 -21
- package/packages/dsh-plugin/dsh/route-guard.js +95 -0
- package/packages/dsh-plugin/dsh/runner.js +49 -6
- package/packages/dsh-plugin/dsh/wide-research.js +20 -18
- package/packages/dsh-plugin/dsh/workbench-client.js +119 -20
- package/packages/dsh-plugin/dsh/workbench-io.js +163 -0
- package/packages/dsh-plugin/dsh/workbench-search.js +385 -0
- package/packages/dsh-plugin/dsh/workbench-suggestions.js +387 -75
- package/packages/dsh-plugin/dsh/workbench.js +234 -497
- package/packages/dsh-plugin/package.json +4 -3
- package/packages/dsh-plugin/scripts/sync-local.mjs +4 -2
- package/packages/dsh-plugin/scripts/sync-local.sh +4 -2
- package/packages/dsh-plugin/test/client.test.js +26 -0
- package/packages/dsh-plugin/test/diagnostics.test.js +5 -2
- package/packages/dsh-plugin/test/index.test.js +150 -1
- package/packages/dsh-plugin/test/workbench-concurrency.test.js +98 -0
- package/packages/dsh-plugin/test/workbench.test.js +337 -9
- package/scripts/adaptive.py +13 -11
- package/scripts/browser_auth.py +178 -4
- package/scripts/cache.py +68 -69
- package/scripts/check_commit_report.py +46 -0
- package/scripts/chrome_cdp.py +71 -0
- package/scripts/circuit_breaker.py +77 -12
- package/scripts/config_cache.py +4 -3
- package/scripts/daemon.py +9 -2
- package/scripts/engine_add.py +45 -0
- package/scripts/engine_dispatch.py +27 -47
- package/scripts/engine_failure.py +33 -0
- package/scripts/engine_fingerprint.py +114 -0
- package/scripts/engine_health.py +130 -0
- package/scripts/engine_states.py +50 -0
- package/scripts/engines_base.py +7 -16
- package/scripts/engines_builders_search.py +19 -8
- package/scripts/engines_builders_tech.py +16 -16
- package/scripts/engines_fields.py +23 -0
- package/scripts/evidence_grounding.py +182 -0
- package/scripts/fetch_browser.py +25 -10
- package/scripts/gate_manifest_check.py +75 -0
- package/scripts/gen_readme_art.py +264 -0
- package/scripts/mcp_transport.py +24 -5
- package/scripts/numeric_verify.py +9 -0
- package/scripts/pre-commit +57 -8
- package/scripts/query_operators.py +229 -1
- package/scripts/quota.py +19 -37
- package/scripts/release.py +16 -1
- package/scripts/research_gates.py +85 -1
- package/scripts/route_combo.py +13 -1
- package/scripts/source_discovery.py +611 -0
- package/scripts/sync_backends.py +45 -0
- package/sub-skills/ego-search/README.md +9 -0
- package/sub-skills/ego-search/scripts/ego_search.py +182 -15
- package/sub-skills/ego-search/scripts/pacing.py +291 -0
- package/sub-skills/ego-search/scripts/quality.py +262 -6
- package/sub-skills/ego-search/scripts/runtime.py +7 -1
- package/sub-skills/ego-search/scripts/site_profiles.py +157 -0
- package/sub-skills/ego-search/scripts/webbridge_adapter.py +7 -1
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @taxueseek/argo-dsh — 控制面路由安全围栏(TCP Peer 主防线 + Host/Origin 纵深)
|
|
3
|
+
*
|
|
4
|
+
* 仅允许本机回环对端访问控制面接口:
|
|
5
|
+
* 1. 当存在底层 TCP socket 时,以 req.socket.remoteAddress 为唯一主判据
|
|
6
|
+
* (无法被客户端伪造,绝不信任 X-Forwarded-For);
|
|
7
|
+
* 2. 叠加 Host 与 Origin 的回环/同源校验,防御本机浏览器的 DNS Rebinding。
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const IPV4_LOOPBACK_RE = /^127\.(?:25[0-5]|2[0-4]\d|1?\d?\d)\.(?:25[0-5]|2[0-4]\d|1?\d?\d)\.(?:25[0-5]|2[0-4]\d|1?\d?\d)$/
|
|
11
|
+
|
|
12
|
+
export function isLoopbackAddress(addr) {
|
|
13
|
+
if (typeof addr !== 'string') return false
|
|
14
|
+
const raw = addr.trim().toLowerCase()
|
|
15
|
+
if (!raw) return false
|
|
16
|
+
if (raw === '::1' || raw === 'localhost') return true
|
|
17
|
+
if (IPV4_LOOPBACK_RE.test(raw)) return true
|
|
18
|
+
if (raw.startsWith('::ffff:')) {
|
|
19
|
+
return IPV4_LOOPBACK_RE.test(raw.slice(7))
|
|
20
|
+
}
|
|
21
|
+
return false
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function extractHostname(hostHeader) {
|
|
25
|
+
if (typeof hostHeader !== 'string' || !hostHeader.trim()) return ''
|
|
26
|
+
try {
|
|
27
|
+
return new URL(`http://${hostHeader.trim()}`).hostname.toLowerCase()
|
|
28
|
+
} catch {
|
|
29
|
+
return ''
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function isLoopbackHost(hostHeader) {
|
|
34
|
+
const host = extractHostname(hostHeader)
|
|
35
|
+
if (!host) return false
|
|
36
|
+
if (host === 'localhost' || host === '[::1]' || host === '::1') return true
|
|
37
|
+
return IPV4_LOOPBACK_RE.test(host)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function checkLoopbackAndOrigin(ctx, req) {
|
|
41
|
+
const peer = req?.socket?.remoteAddress ?? req?.connection?.remoteAddress ?? req?.remoteAddress
|
|
42
|
+
if (peer !== undefined && peer !== null && peer !== '') {
|
|
43
|
+
if (!isLoopbackAddress(String(peer))) return false
|
|
44
|
+
} else if (!isLoopbackHost(req?.headers?.host)) {
|
|
45
|
+
return false
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const hostHeader = req?.headers?.host
|
|
49
|
+
if (hostHeader && !isLoopbackHost(hostHeader)) {
|
|
50
|
+
const expected = ctx?.webServer?.getOrigin?.()
|
|
51
|
+
if (!expected) return false
|
|
52
|
+
try {
|
|
53
|
+
const expectedHost = new URL(expected).hostname.toLowerCase()
|
|
54
|
+
if (extractHostname(hostHeader) !== expectedHost) return false
|
|
55
|
+
} catch {
|
|
56
|
+
return false
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const origin = req?.headers?.origin
|
|
61
|
+
if (!origin) return true
|
|
62
|
+
try {
|
|
63
|
+
const expected = ctx?.webServer?.getOrigin?.()
|
|
64
|
+
if (expected && origin === expected) return true
|
|
65
|
+
const parsed = new URL(origin)
|
|
66
|
+
return isLoopbackAddress(parsed.hostname)
|
|
67
|
+
} catch {
|
|
68
|
+
return false
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** 查询登录态 Profile 列表,并对冷启动未核验站点后台静默触发一次活体复核(60s 缓存)。 */
|
|
73
|
+
export async function resolveAuthStatusWithBgVerify({ runCli, verifyCache, inflight, allowVerify = true }) {
|
|
74
|
+
let profiles = []
|
|
75
|
+
try {
|
|
76
|
+
const out = await runCli(['auth', 'status', '--json'])
|
|
77
|
+
profiles = Array.isArray(out?.profiles) ? out.profiles : []
|
|
78
|
+
} catch {
|
|
79
|
+
profiles = []
|
|
80
|
+
}
|
|
81
|
+
const now = Date.now()
|
|
82
|
+
return profiles.map((p) => {
|
|
83
|
+
const site = String(p?.site || '')
|
|
84
|
+
const cached = verifyCache.get(site)
|
|
85
|
+
const fresh = cached && (now - cached.ts < 60_000) ? cached.data : null
|
|
86
|
+
if (site && !fresh && !inflight.has(site) && allowVerify) {
|
|
87
|
+
inflight.add(site)
|
|
88
|
+
runCli(['auth', 'verify', site, '--json'])
|
|
89
|
+
.then((v) => { verifyCache.set(site, { ts: Date.now(), data: v }) })
|
|
90
|
+
.catch(() => {})
|
|
91
|
+
.finally(() => { inflight.delete(site) })
|
|
92
|
+
}
|
|
93
|
+
return { ...p, verification: fresh || { pending: Boolean(site) } }
|
|
94
|
+
})
|
|
95
|
+
}
|
|
@@ -80,6 +80,7 @@ export const DEFAULTS = Object.freeze({
|
|
|
80
80
|
'FOURGET_URL',
|
|
81
81
|
'GEMINI_API_KEY',
|
|
82
82
|
'GITHUB_TOKEN',
|
|
83
|
+
'HELVE_API_KEY',
|
|
83
84
|
'KEENABLE_API_KEY',
|
|
84
85
|
'METASO_API_KEY',
|
|
85
86
|
'OCTEN_API_KEY',
|
|
@@ -295,8 +296,9 @@ export function createMcpConnection(options) {
|
|
|
295
296
|
return initPromise
|
|
296
297
|
},
|
|
297
298
|
request: (method, params, timeoutMs = 0) => {
|
|
299
|
+
const p = send(method, params, timeoutMs)
|
|
298
300
|
if (claims > 0) claims -= 1
|
|
299
|
-
return
|
|
301
|
+
return p
|
|
300
302
|
},
|
|
301
303
|
claim: () => {
|
|
302
304
|
claims += 1
|
|
@@ -361,10 +363,13 @@ export async function acquireMcp(options, signal) {
|
|
|
361
363
|
if (mcpPool.length >= max) throw err
|
|
362
364
|
}
|
|
363
365
|
}
|
|
366
|
+
const envCfg = (options.config && ('keyRefs' in options.config || 'argoEnv' in options.config))
|
|
367
|
+
? options.config
|
|
368
|
+
: undefined
|
|
364
369
|
if (mcpPool.length < max) {
|
|
365
370
|
const conn = createMcpConnection({
|
|
366
371
|
...options,
|
|
367
|
-
envResolver: () => resolveEnv(options),
|
|
372
|
+
envResolver: () => resolveEnv(options, envCfg),
|
|
368
373
|
configKey: targetConfigKey,
|
|
369
374
|
})
|
|
370
375
|
mcpPool.push(conn)
|
|
@@ -378,7 +383,29 @@ export async function acquireMcp(options, signal) {
|
|
|
378
383
|
}
|
|
379
384
|
return conn
|
|
380
385
|
}
|
|
381
|
-
const
|
|
386
|
+
const matching = mcpPool.filter(entry => entry.configKey === undefined || entry.configKey === targetConfigKey)
|
|
387
|
+
if (matching.length === 0) {
|
|
388
|
+
// 满池且全部为旧 configKey 的忙连接:不可关闭在跑的连接,只能新建一条
|
|
389
|
+
// 临时超限(pool 瞬时 > max)。超限是自限的:函数开头会把空转的旧
|
|
390
|
+
// configKey 连接回收,新建的匹配连接下次会被 354 行的 idle 分支复用,
|
|
391
|
+
// 池随之收敛回 max 以内(2026-11-21 审计:原注释「替换最闲旧连接」与代码不符)
|
|
392
|
+
const conn = createMcpConnection({
|
|
393
|
+
...options,
|
|
394
|
+
envResolver: () => resolveEnv(options, envCfg),
|
|
395
|
+
configKey: targetConfigKey,
|
|
396
|
+
})
|
|
397
|
+
mcpPool.push(conn)
|
|
398
|
+
conn.claim()
|
|
399
|
+
try {
|
|
400
|
+
await initializeWithSignal(conn, initMs, signal)
|
|
401
|
+
} catch (err) {
|
|
402
|
+
dropFromPool(conn)
|
|
403
|
+
conn.close()
|
|
404
|
+
throw err
|
|
405
|
+
}
|
|
406
|
+
return conn
|
|
407
|
+
}
|
|
408
|
+
const least = matching.reduce((a, b) => (a.load() <= b.load() ? a : b))
|
|
382
409
|
least.claim()
|
|
383
410
|
try {
|
|
384
411
|
await initializeWithSignal(least, initMs, signal)
|
|
@@ -477,7 +504,11 @@ export async function fetchViaArgo(url, signal, options = {}, deps = {}) {
|
|
|
477
504
|
return
|
|
478
505
|
}
|
|
479
506
|
const text = value?.content?.[0]?.text
|
|
480
|
-
|
|
507
|
+
try {
|
|
508
|
+
resolve(typeof text === 'string' ? JSON.parse(text) : {})
|
|
509
|
+
} catch (parseErr) {
|
|
510
|
+
reject(argoToolError(`argo_fetch returned invalid JSON: ${parseErr.message}`))
|
|
511
|
+
}
|
|
481
512
|
}, (err) => {
|
|
482
513
|
if (signal !== undefined) signal.removeEventListener('abort', onAbort)
|
|
483
514
|
reject(err)
|
|
@@ -616,12 +647,24 @@ export function runNativeCall({ command, args, env }, timeoutMs, signal) {
|
|
|
616
647
|
signal.addEventListener('abort', onAbort, { once: true })
|
|
617
648
|
detachAbort = () => signal.removeEventListener('abort', onAbort)
|
|
618
649
|
}
|
|
650
|
+
const MAX_NATIVE_BYTES = 4 * 1024 * 1024
|
|
651
|
+
let stdoutBytes = 0
|
|
652
|
+
let stderrBytes = 0
|
|
619
653
|
timer = setTimeout(() => {
|
|
620
654
|
try { child.kill('SIGKILL') } catch { /* already gone */ }
|
|
621
655
|
settle(reject, new Error(`argo native call timed out after ${timeoutMs}ms`))
|
|
622
656
|
}, timeoutMs)
|
|
623
|
-
|
|
624
|
-
child.
|
|
657
|
+
if (typeof timer.unref === 'function') timer.unref()
|
|
658
|
+
child.stdout.setEncoding('utf8')
|
|
659
|
+
child.stderr.setEncoding('utf8')
|
|
660
|
+
child.stdout.on('data', (chunk) => {
|
|
661
|
+
stdoutBytes += Buffer.byteLength(chunk, 'utf8')
|
|
662
|
+
if (stdoutBytes <= MAX_NATIVE_BYTES) stdout += chunk
|
|
663
|
+
})
|
|
664
|
+
child.stderr.on('data', (chunk) => {
|
|
665
|
+
stderrBytes += Buffer.byteLength(chunk, 'utf8')
|
|
666
|
+
if (stderrBytes <= 256 * 1024) stderr += chunk
|
|
667
|
+
})
|
|
625
668
|
child.on('error', (err) => settle(reject, err))
|
|
626
669
|
child.on('close', (code) => {
|
|
627
670
|
if (code === 0) { settle(resolve, stdout); return }
|
|
@@ -704,16 +704,21 @@ export function createWideResearchTool(ctx, config, options = {}) {
|
|
|
704
704
|
const localSources = buildLocalSources(fileInputs)
|
|
705
705
|
let recomputedValues = []
|
|
706
706
|
let recomputeExpected = false
|
|
707
|
+
let recomputeWarning = null
|
|
707
708
|
if (recomputeSpec && recomputeSpec.script) {
|
|
708
709
|
recomputeExpected = true
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
710
|
+
try {
|
|
711
|
+
recomputedValues = await runRecomputeForResearch(recomputeSpec, fileInputs, {
|
|
712
|
+
command: config.searchCommand,
|
|
713
|
+
args: config.searchArgs,
|
|
714
|
+
timeoutMs: config.searchTimeoutMs,
|
|
715
|
+
idleMs: config.searchIdleMs,
|
|
716
|
+
max: config.searchConcurrency,
|
|
717
|
+
config,
|
|
718
|
+
}, exec.signal)
|
|
719
|
+
} catch (err) {
|
|
720
|
+
recomputeWarning = `recompute_skipped: ${clip(String(err?.message || err), 200)}`
|
|
721
|
+
}
|
|
717
722
|
}
|
|
718
723
|
|
|
719
724
|
const planPrompt = [
|
|
@@ -768,12 +773,16 @@ export function createWideResearchTool(ctx, config, options = {}) {
|
|
|
768
773
|
|
|
769
774
|
const completed = outcomes.filter(outcome => outcome.result)
|
|
770
775
|
const failed = outcomes.filter(outcome => outcome.error)
|
|
771
|
-
const warnings = [
|
|
776
|
+
const warnings = [
|
|
777
|
+
...(recomputeWarning ? [recomputeWarning] : []),
|
|
778
|
+
...stageWarnings,
|
|
779
|
+
...failed.map(outcome => `${outcome.track.title}: ${outcome.error}`),
|
|
780
|
+
]
|
|
772
781
|
if (!completed.length) throw new Error(`wide_research could not complete any research tracks: ${warnings.join('; ')}`)
|
|
773
782
|
|
|
774
783
|
const sources = []
|
|
775
784
|
const seenUrls = new Set()
|
|
776
|
-
completed.map(outcome => {
|
|
785
|
+
const researchLedger = completed.map(outcome => {
|
|
777
786
|
const sourceKeys = []
|
|
778
787
|
for (const source of outcome.result.sources) {
|
|
779
788
|
const normalizedUrl = normalizeSourceUrl(source.url)
|
|
@@ -797,14 +806,7 @@ export function createWideResearchTool(ctx, config, options = {}) {
|
|
|
797
806
|
question,
|
|
798
807
|
scope,
|
|
799
808
|
responseLanguage: language,
|
|
800
|
-
researchLedger
|
|
801
|
-
track: outcome.track,
|
|
802
|
-
summary: outcome.result.summary,
|
|
803
|
-
findings: outcome.result.findings,
|
|
804
|
-
sourceKeys: outcome.result.sources.map(s => s.key).filter(Boolean),
|
|
805
|
-
disagreements: outcome.result.disagreements,
|
|
806
|
-
gaps: outcome.result.gaps,
|
|
807
|
-
})),
|
|
809
|
+
researchLedger,
|
|
808
810
|
sources,
|
|
809
811
|
localSources,
|
|
810
812
|
recomputedValues,
|
|
@@ -11,6 +11,10 @@ import { CSS, renderMarkdown } from '/argo/workbench-md.js'
|
|
|
11
11
|
|
|
12
12
|
const STATE_KEY = 'argo-workbench:state.v1'
|
|
13
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'
|
|
14
18
|
|
|
15
19
|
const CORE_MODES = [
|
|
16
20
|
{ id: 'general', label: '全网搜索', desc: '多源快查,先给结论再列出处', ph: '搜任何问题、概念、报错或资料(Enter 发送,Shift+Enter 换行)…' },
|
|
@@ -144,17 +148,20 @@ export function mountArgoWorkbench(ctx, react) {
|
|
|
144
148
|
}
|
|
145
149
|
|
|
146
150
|
function WorkbenchApp() {
|
|
147
|
-
const
|
|
151
|
+
const [initialSaved] = useState(() => readStorage(STATE_KEY, null))
|
|
148
152
|
const [prefs, setPrefs] = useState(() => readStorage(PREFS_KEY, { selection: true }))
|
|
149
153
|
const [lang, setLang] = useState(resolveLang)
|
|
150
154
|
const [view, setView] = useState('home')
|
|
151
155
|
const [input, setInput] = useState('')
|
|
152
|
-
const [activeQuery, setActiveQuery] = useState(
|
|
156
|
+
const [activeQuery, setActiveQuery] = useState(() => initialSaved?.query || '')
|
|
153
157
|
const [mode, setMode] = useState('general')
|
|
154
158
|
const [topicSamples, setTopicSamples] = useState(() => Object.fromEntries(TOPIC_CARDS.map(t => [t.id, pickSample(t.samples)])))
|
|
155
159
|
const [suggestions, setSuggestions] = useState([])
|
|
156
|
-
const [
|
|
157
|
-
const [
|
|
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 || [])
|
|
158
165
|
const [stageText, setStageText] = useState('')
|
|
159
166
|
const [loading, setLoading] = useState(false)
|
|
160
167
|
const [filter, setFilter] = useState('all')
|
|
@@ -173,10 +180,18 @@ export function mountArgoWorkbench(ctx, react) {
|
|
|
173
180
|
const inputRef = useRef(null)
|
|
174
181
|
const esRef = useRef(null)
|
|
175
182
|
const abortRef = useRef(null)
|
|
183
|
+
const modeRef = useRef(mode)
|
|
184
|
+
const startSearchRef = useRef(null)
|
|
185
|
+
const suggestSeqRef = useRef(0)
|
|
186
|
+
modeRef.current = mode
|
|
176
187
|
|
|
177
188
|
useEffect(() => {
|
|
178
|
-
|
|
179
|
-
|
|
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])
|
|
180
195
|
|
|
181
196
|
const refreshWatches = async () => {
|
|
182
197
|
try {
|
|
@@ -187,10 +202,14 @@ export function mountArgoWorkbench(ctx, react) {
|
|
|
187
202
|
}
|
|
188
203
|
|
|
189
204
|
const refreshSuggestions = async (targetMode = mode, targetLang = lang, shuffle = false) => {
|
|
205
|
+
const seq = ++suggestSeqRef.current
|
|
190
206
|
try {
|
|
191
207
|
const res = await fetch(`/argo/api/suggestions?mode=${encodeURIComponent(targetMode)}&lang=${encodeURIComponent(targetLang)}&shuffle=${shuffle ? '1' : '0'}`)
|
|
192
208
|
const data = await res.json()
|
|
193
|
-
if (Array.isArray(data?.items))
|
|
209
|
+
if (seq === suggestSeqRef.current && Array.isArray(data?.items)) {
|
|
210
|
+
setSuggestions(data.items)
|
|
211
|
+
if (data.meta) setHotspotMeta(prev => ({ ...prev, ...data.meta }))
|
|
212
|
+
}
|
|
194
213
|
} catch { /* ignore */ }
|
|
195
214
|
}
|
|
196
215
|
|
|
@@ -236,10 +255,6 @@ export function mountArgoWorkbench(ctx, react) {
|
|
|
236
255
|
es.addEventListener('evidence', (ev) => { const d = parse(ev); if (d && (d.crossValidation || d.summary)) setEvidenceSummary(d) })
|
|
237
256
|
es.addEventListener('cards', (ev) => { const d = parse(ev); if (Array.isArray(d.cards)) setCards(d.cards) })
|
|
238
257
|
es.addEventListener('gate', (ev) => { const d = parse(ev); if (typeof d.passed === 'boolean') setGateResult(d) })
|
|
239
|
-
es.addEventListener('verify-update', (ev) => {
|
|
240
|
-
const d = parse(ev)
|
|
241
|
-
if (d.card) setCards(prev => prev.map(c => c.id === d.card.id ? d.card : c))
|
|
242
|
-
})
|
|
243
258
|
es.addEventListener('answer', (ev) => {
|
|
244
259
|
const d = parse(ev)
|
|
245
260
|
if (!d.delta) return
|
|
@@ -253,14 +268,19 @@ export function mountArgoWorkbench(ctx, react) {
|
|
|
253
268
|
es.addEventListener('answer-status', (ev) => { const d = parse(ev); if (d.message) setStageText(d.message) })
|
|
254
269
|
es.addEventListener('done', () => { setLoading(false); setStageText(''); es.close(); esRef.current = null })
|
|
255
270
|
es.addEventListener('failure', (ev) => { const d = parse(ev); setLoading(false); setStageText(`检索出错:${d.message || '未知错误'}`); es.close(); esRef.current = null })
|
|
256
|
-
es.onerror = () => {
|
|
271
|
+
es.onerror = () => {
|
|
272
|
+
es.close()
|
|
273
|
+
if (esRef.current === es) esRef.current = null
|
|
274
|
+
setLoading(false)
|
|
275
|
+
}
|
|
257
276
|
}
|
|
277
|
+
startSearchRef.current = startSearch
|
|
258
278
|
|
|
259
279
|
useEffect(() => {
|
|
260
280
|
const handler = (req) => {
|
|
261
281
|
if (!req) return
|
|
262
282
|
pendingExternal = null
|
|
263
|
-
|
|
283
|
+
startSearchRef.current?.(req.query, req.mode || modeRef.current)
|
|
264
284
|
}
|
|
265
285
|
listeners.add(handler)
|
|
266
286
|
if (pendingExternal) handler(pendingExternal)
|
|
@@ -291,6 +311,10 @@ export function mountArgoWorkbench(ctx, react) {
|
|
|
291
311
|
body: JSON.stringify({ query: activeQuery, mode, cards, history: historySnapshot, question: q }),
|
|
292
312
|
signal: ac.signal,
|
|
293
313
|
})
|
|
314
|
+
if (!res.ok || !res.body) {
|
|
315
|
+
setStageText(`追问失败(HTTP ${res.status})`)
|
|
316
|
+
return
|
|
317
|
+
}
|
|
294
318
|
const reader = res.body.getReader()
|
|
295
319
|
const dec = new TextDecoder()
|
|
296
320
|
let buf = ''
|
|
@@ -305,7 +329,8 @@ export function mountArgoWorkbench(ctx, react) {
|
|
|
305
329
|
const dataMatch = chunk.match(/^data:\s*(.+)$/m)
|
|
306
330
|
if (!dataMatch) continue
|
|
307
331
|
const evName = evMatch ? evMatch[1].trim() : 'message'
|
|
308
|
-
|
|
332
|
+
let payload
|
|
333
|
+
try { payload = JSON.parse(dataMatch[1]) } catch { continue }
|
|
309
334
|
if (evName === 'answer' && payload.delta) {
|
|
310
335
|
setTurns(prev => {
|
|
311
336
|
const next = [...prev]
|
|
@@ -313,6 +338,8 @@ export function mountArgoWorkbench(ctx, react) {
|
|
|
313
338
|
if (last && last.role === 'assistant') next[next.length - 1] = { ...last, text: last.text + payload.delta }
|
|
314
339
|
return next
|
|
315
340
|
})
|
|
341
|
+
} else if (evName === 'failure' && payload.message) {
|
|
342
|
+
setStageText(`追问出错:${payload.message}`)
|
|
316
343
|
}
|
|
317
344
|
}
|
|
318
345
|
}
|
|
@@ -335,7 +362,7 @@ export function mountArgoWorkbench(ctx, react) {
|
|
|
335
362
|
const data = await res.json()
|
|
336
363
|
if (Array.isArray(data.items)) setWatches(data.items)
|
|
337
364
|
setWatchQuery('')
|
|
338
|
-
|
|
365
|
+
setPopover('watch') // 抽屉可见性由 popover 状态管(此前引用未定义的 setWatchOpen)
|
|
339
366
|
} catch { /* ignore */ }
|
|
340
367
|
}
|
|
341
368
|
|
|
@@ -369,7 +396,7 @@ export function mountArgoWorkbench(ctx, react) {
|
|
|
369
396
|
setMode(w.mode || 'general')
|
|
370
397
|
setCards(Array.isArray(w.lastCards) ? w.lastCards : [])
|
|
371
398
|
setTurns([{ role: 'assistant', text: w.lastSummary || '该定时任务尚未生成摘要,可点击「立即执行」或「强制刷新」。' }])
|
|
372
|
-
|
|
399
|
+
setPopover(null)
|
|
373
400
|
}
|
|
374
401
|
|
|
375
402
|
const scrollToCard = (cardId) => {
|
|
@@ -414,6 +441,49 @@ export function mountArgoWorkbench(ctx, react) {
|
|
|
414
441
|
if (next === 'settings') refreshHealth()
|
|
415
442
|
}
|
|
416
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
|
+
|
|
417
487
|
const toggleEgoSearch = async () => {
|
|
418
488
|
const current = Boolean(healthInfo?.egoSearch?.enabled)
|
|
419
489
|
try {
|
|
@@ -484,7 +554,22 @@ export function mountArgoWorkbench(ctx, react) {
|
|
|
484
554
|
if (view === 'home') {
|
|
485
555
|
return h('div', { className: 'aw-root' },
|
|
486
556
|
h('div', { className: 'aw-hero' },
|
|
487
|
-
h('div', { className: 'aw-hero-top' },
|
|
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' : '刷新热点'))),
|
|
488
573
|
h('button', { type: 'button', className: 'aw-icon-btn', onClick: toggleWatchPanel }, `定时搜索 (${watches.length})`)),
|
|
489
574
|
renderWatchDrawer(),
|
|
490
575
|
h('div', { className: 'aw-hero-inner' },
|
|
@@ -641,9 +726,18 @@ export function mountArgoWorkbench(ctx, react) {
|
|
|
641
726
|
h('label', { style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', cursor: 'pointer', marginBottom: '8px' } },
|
|
642
727
|
h('span', null, '对话划词浮层(Argo 分析)'),
|
|
643
728
|
h('input', { type: 'checkbox', checked: Boolean(prefs.selection), onChange: toggleSelectionPref })),
|
|
644
|
-
h('label', { style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', cursor: 'pointer' } },
|
|
729
|
+
h('label', { style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', cursor: 'pointer', marginBottom: '8px' } },
|
|
645
730
|
h('span', null, '登录态专业搜索(ego-search)'),
|
|
646
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 || '刷新')))),
|
|
647
741
|
h('button', {
|
|
648
742
|
type: 'button',
|
|
649
743
|
className: 'aw-icon-btn',
|
|
@@ -665,7 +759,7 @@ export function mountArgoWorkbench(ctx, react) {
|
|
|
665
759
|
}, `交叉验证:${evidenceSummary.crossValidation.corroboration_level || 'unknown'}${evidenceSummary.summary ? ` · 高可信 ${evidenceSummary.summary.high_credibility || 0}` : ''}`) : null,
|
|
666
760
|
gateResult ? h('span', {
|
|
667
761
|
className: 'aw-badge',
|
|
668
|
-
title: (gateResult.warnings || []).join(';'),
|
|
762
|
+
title: (gateResult.warnings || []).map(w => (typeof w === 'string' ? w : (w?.detail || w?.id || ''))).filter(Boolean).join(';'),
|
|
669
763
|
style: { background: gateResult.passed ? 'var(--aw-sunken)' : '#fef2f2', color: gateResult.passed ? 'var(--aw-text-2)' : '#b91c1c' },
|
|
670
764
|
}, gateResult.passed ? '质量门禁通过' : '质量门禁未达标') : null),
|
|
671
765
|
clarifyInfo ? h('div', { style: { fontSize: '12px', color: 'var(--aw-text-2)', padding: '6px 10px', marginBottom: '10px', borderRadius: '8px', background: 'var(--aw-sunken)' } },
|
|
@@ -736,6 +830,7 @@ export function mountArgoWorkbench(ctx, react) {
|
|
|
736
830
|
const [hit, setHit] = useState(null)
|
|
737
831
|
|
|
738
832
|
useEffect(() => {
|
|
833
|
+
let timerId = null
|
|
739
834
|
const checkSelection = () => {
|
|
740
835
|
const prefs = readStorage(PREFS_KEY, { selection: true })
|
|
741
836
|
if (!prefs.selection) { setHit(null); return }
|
|
@@ -748,10 +843,14 @@ export function mountArgoWorkbench(ctx, react) {
|
|
|
748
843
|
if (!rect || (rect.width === 0 && rect.height === 0)) { setHit(null); return }
|
|
749
844
|
setHit({ text, top: Math.max(12, rect.top - 38), left: Math.min(window.innerWidth - 130, Math.max(12, rect.left)) })
|
|
750
845
|
}
|
|
751
|
-
const onUp = () =>
|
|
846
|
+
const onUp = () => {
|
|
847
|
+
if (timerId) clearTimeout(timerId)
|
|
848
|
+
timerId = setTimeout(checkSelection, 20)
|
|
849
|
+
}
|
|
752
850
|
document.addEventListener('mouseup', onUp)
|
|
753
851
|
document.addEventListener('keyup', onUp)
|
|
754
852
|
return () => {
|
|
853
|
+
if (timerId) clearTimeout(timerId)
|
|
755
854
|
document.removeEventListener('mouseup', onUp)
|
|
756
855
|
document.removeEventListener('keyup', onUp)
|
|
757
856
|
}
|