argo-search 2.14.0 → 2.15.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 (207) hide show
  1. package/AGENTS.md +8 -6
  2. package/README.es.md +56 -824
  3. package/README.ja.md +55 -825
  4. package/README.ko.md +55 -823
  5. package/README.md +128 -868
  6. package/README.zh.md +206 -0
  7. package/SKILL.md +17 -18
  8. package/assets/readme/counts.json +1 -1
  9. package/assets/readme/hero.svg +23 -23
  10. package/backends/concept_vectors.bin +0 -0
  11. package/backends/domain_profiles.json +66 -0
  12. package/backends/engine_concept_vectors.json +1525 -1525
  13. package/backends/engine_registry.yaml +193 -46
  14. package/backends/quota_profiles.json +110 -0
  15. package/bin/argo +30 -17
  16. package/config.yaml +196 -36
  17. package/docs/ADDING_NEW_ENGINE.md +10 -0
  18. package/docs/ARGO_INTRO.md +1 -1
  19. package/docs/CHANGELOG.md +45 -0
  20. package/docs/ENGINE_CATALOG.md +128 -112
  21. package/docs/MCP_SETUP.md +2 -2
  22. package/docs/RELEASE_NOTES_v2.14.0.md +12 -1
  23. package/docs/RELEASE_NOTES_v2.14.1.md +80 -0
  24. package/docs/RELEASE_NOTES_v2.15.0.md +50 -0
  25. package/docs/RELEASING.md +53 -1
  26. package/engines/specs/ai_labs.yaml +89 -0
  27. package/engines/specs/artic.yaml +11 -1
  28. package/engines/specs/bilibili_hot.yaml +11 -1
  29. package/engines/specs/brave.yaml +3 -3
  30. package/engines/specs/cisa_alerts.yaml +40 -0
  31. package/engines/specs/cleveland.yaml +15 -1
  32. package/engines/specs/clinicaltrials.yaml +16 -1
  33. package/engines/specs/cn_ai_news.yaml +10 -8
  34. package/engines/specs/cnii.yaml +15 -4
  35. package/engines/specs/deezer.yaml +12 -1
  36. package/engines/specs/digup.yaml +11 -6
  37. package/engines/specs/doaj.yaml +14 -1
  38. package/engines/specs/douyin_hot.yaml +11 -1
  39. package/engines/specs/dw_news.yaml +4 -2
  40. package/engines/specs/endoflife.yaml +16 -1
  41. package/engines/specs/eng_blogs.yaml +63 -0
  42. package/engines/specs/eu_opendata.yaml +11 -1
  43. package/engines/specs/europeana.yaml +22 -5
  44. package/engines/specs/feed.yaml +62 -0
  45. package/engines/specs/felo.yaml +3 -3
  46. package/engines/specs/figshare.yaml +12 -1
  47. package/engines/specs/firecrawl.yaml +3 -0
  48. package/engines/specs/fourget.yaml +5 -2
  49. package/engines/specs/france24.yaml +6 -4
  50. package/engines/specs/fxtwitter.yaml +29 -6
  51. package/engines/specs/grepapp_mcp.yaml +62 -0
  52. package/engines/specs/guardian_rss.yaml +6 -4
  53. package/engines/specs/hackernews.yaml +17 -2
  54. package/engines/specs/hal.yaml +19 -1
  55. package/engines/specs/hf_datasets.yaml +59 -0
  56. package/engines/specs/hf_papers.yaml +17 -1
  57. package/engines/specs/itotii.yaml +13 -1
  58. package/engines/specs/jikan.yaml +12 -10
  59. package/engines/specs/kaggle.yaml +5 -3
  60. package/engines/specs/lobsters.yaml +41 -0
  61. package/engines/specs/local_seek.yaml +6 -0
  62. package/engines/specs/maven.yaml +61 -0
  63. package/engines/specs/nasa_cmr.yaml +12 -1
  64. package/engines/specs/nuget.yaml +57 -0
  65. package/engines/specs/open_meteo.yaml +1 -1
  66. package/engines/specs/redskill.yaml +2 -0
  67. package/engines/specs/searxng.yaml +4 -2
  68. package/engines/specs/sec_edgar.yaml +8 -3
  69. package/engines/specs/tatoeba.yaml +14 -1
  70. package/engines/specs/tinyfish.yaml +2 -0
  71. package/engines/specs/tinyfish_news.yaml +2 -0
  72. package/engines/specs/tinyfish_paper.yaml +2 -0
  73. package/engines/specs/toutiao_hot.yaml +11 -1
  74. package/engines/specs/train.yaml +3 -0
  75. package/engines/specs/tvmaze.yaml +5 -1
  76. package/engines/specs/twitter.yaml +4 -0
  77. package/engines/specs/unpaywall.yaml +6 -0
  78. package/engines/specs/usda.yaml +14 -1
  79. package/engines/specs/vam.yaml +17 -3
  80. package/engines/specs/weibo_hot.yaml +11 -1
  81. package/engines/specs/wolframalpha.yaml +3 -3
  82. package/engines/specs/xiaohongshu.yaml +2 -0
  83. package/engines/specs/zhihu.yaml +3 -18
  84. package/engines/specs/zhihu_kb.yaml +18 -0
  85. package/engines/specs/zhihu_questions.yaml +19 -0
  86. package/package.json +4 -2
  87. package/packages/dsh-plugin/README.md +9 -14
  88. package/packages/dsh-plugin/dsh/client.js +467 -1024
  89. package/packages/dsh-plugin/dsh/diagnostics.js +71 -20
  90. package/packages/dsh-plugin/dsh/native-tools.mjs +61 -113
  91. package/packages/dsh-plugin/dsh/runner.js +2 -0
  92. package/packages/dsh-plugin/dsh/wide-research.js +1 -1
  93. package/packages/dsh-plugin/package.json +8 -3
  94. package/packages/dsh-plugin/scripts/sync-local.mjs +87 -0
  95. package/packages/dsh-plugin/scripts/sync-local.sh +13 -1
  96. package/packages/dsh-plugin/test/diagnostics.test.js +38 -1
  97. package/packages/dsh-plugin/test/size-gate.test.js +2 -9
  98. package/scripts/adaptive.py +7 -1
  99. package/scripts/archive_run.py +112 -53
  100. package/scripts/argo_paths.py +40 -3
  101. package/scripts/badcase_ledger.py +153 -10
  102. package/scripts/build_concept_table.py +112 -55
  103. package/scripts/build_release_assets.sh +43 -15
  104. package/scripts/cache.py +5 -1
  105. package/scripts/caliber_isolation.py +60 -23
  106. package/scripts/circuit_breaker.py +56 -8
  107. package/scripts/cli_io.py +20 -2
  108. package/scripts/config_cache.py +31 -0
  109. package/scripts/daemon.py +146 -51
  110. package/scripts/dormant_ledger.py +239 -0
  111. package/scripts/engine_dispatch.py +3 -3
  112. package/scripts/engine_env.py +182 -1
  113. package/scripts/engine_families.py +50 -7
  114. package/scripts/engine_states.py +9 -51
  115. package/scripts/engine_validate.py +150 -6
  116. package/scripts/engines.py +15 -67
  117. package/scripts/engines_base.py +68 -124
  118. package/scripts/engines_builders.py +0 -51
  119. package/scripts/engines_builders_batch10.py +346 -100
  120. package/scripts/engines_builders_batch11.py +2 -75
  121. package/scripts/engines_builders_batch9.py +15 -228
  122. package/scripts/engines_builders_cn.py +0 -194
  123. package/scripts/engines_builders_feeds.py +203 -35
  124. package/scripts/engines_builders_intl.py +15 -443
  125. package/scripts/engines_builders_pixiv.py +2 -16
  126. package/scripts/engines_builders_science.py +0 -85
  127. package/scripts/engines_builders_search.py +7 -14
  128. package/scripts/engines_builders_tech.py +5 -112
  129. package/scripts/engines_builders_weather.py +236 -0
  130. package/scripts/engines_fields.py +91 -0
  131. package/scripts/engines_http.py +135 -0
  132. package/scripts/engines_mcp.py +383 -0
  133. package/scripts/engines_parsers.py +196 -27
  134. package/scripts/engines_schema_drift.py +260 -0
  135. package/scripts/evidence.py +13 -0
  136. package/scripts/evidence_loop.py +93 -5
  137. package/scripts/fetch_jsrun.py +15 -11
  138. package/scripts/fetch_v3.py +28 -28
  139. package/scripts/fulltext_store.py +42 -1
  140. package/scripts/fxtwitter_api.py +8 -7
  141. package/scripts/gen_engine_catalog.py +4 -4
  142. package/scripts/gen_native_tools.py +2 -1
  143. package/scripts/general_pool.py +15 -4
  144. package/scripts/health_check.py +1 -1
  145. package/scripts/link_source.py +65 -24
  146. package/scripts/local_intent.py +51 -15
  147. package/scripts/local_seek.py +37 -4
  148. package/scripts/local_seek_adapter.py +57 -17
  149. package/scripts/mcp_handlers.py +173 -99
  150. package/scripts/mcp_handlers_surface.py +6 -18
  151. package/scripts/mcp_server.py +1 -1
  152. package/scripts/mcp_tools.py +143 -61
  153. package/scripts/mcp_transport.py +42 -10
  154. package/scripts/min_version_scan.py +7 -3
  155. package/scripts/network_aware.py +7 -13
  156. package/scripts/pre-commit +57 -31
  157. package/scripts/query_understanding.py +30 -6
  158. package/scripts/quota.py +6 -1
  159. package/scripts/rank_signals.py +9 -0
  160. package/scripts/recompute.py +15 -5
  161. package/scripts/recovery.py +21 -15
  162. package/scripts/release.py +29 -32
  163. package/scripts/release_check.py +6 -26
  164. package/scripts/replay_eval.py +2 -2
  165. package/scripts/research_cli.py +40 -0
  166. package/scripts/research_notes.py +368 -0
  167. package/scripts/route.py +32 -70
  168. package/scripts/route_audit.py +259 -0
  169. package/scripts/route_combo.py +10 -4
  170. package/scripts/route_domains.py +150 -23
  171. package/scripts/route_lang.py +20 -7
  172. package/scripts/route_log.py +26 -9
  173. package/scripts/route_policy.py +91 -7
  174. package/scripts/route_telemetry_export.py +199 -0
  175. package/scripts/rrf_classic.py +5 -22
  176. package/scripts/search.py +2 -1
  177. package/scripts/search_attribution.py +33 -10
  178. package/scripts/search_cli.py +44 -7
  179. package/scripts/search_entry.py +5 -1
  180. package/scripts/search_output.py +5 -4
  181. package/scripts/search_pipeline.py +12 -0
  182. package/scripts/search_rank.py +21 -11
  183. package/scripts/secret_guard.py +106 -0
  184. package/scripts/semantic_evidence.py +539 -117
  185. package/scripts/settings_page.py +83 -11
  186. package/scripts/social_engines/xiaohongshu_engine.py +2 -1
  187. package/scripts/social_engines/zhihu_engine.py +251 -43
  188. package/scripts/sogou_weixin_browser.py +5 -6
  189. package/scripts/source_audit.py +77 -0
  190. package/scripts/source_ledger.py +2 -15
  191. package/scripts/source_selection.py +45 -20
  192. package/scripts/straggler_policy.py +1 -2
  193. package/scripts/sync_backends.py +24 -0
  194. package/scripts/tfidf_router.py +23 -11
  195. package/scripts/time_utils.py +54 -1
  196. package/scripts/train.py +68 -2
  197. package/scripts/usage_log.py +26 -1
  198. package/sub-skills/argo-wide-research/SKILL.md +68 -0
  199. package/sub-skills/ego-search/SKILL.md +1 -1
  200. package/sub-skills/local-seek/scripts/seek_fts.py +67 -4
  201. package/README.en.md +0 -826
  202. package/scripts/caliber_dedupe.py +0 -66
  203. package/scripts/engines_builders_batch16.py +0 -186
  204. package/scripts/health_probe.py +0 -253
  205. package/scripts/image_vision/vision_probe +0 -0
  206. package/scripts/social_engines/twitter_engine.py +0 -514
  207. package/scripts/sync_installs.py +0 -29
@@ -26,98 +26,29 @@ from typing import Any
26
26
 
27
27
  from engines_base import safe_search, _http_get_raw, http_open, rank_score
28
28
  from bounded_run import run_bounded
29
+ from engines_http import (
30
+ UA as _UA,
31
+ encode_url as _encode_url,
32
+ http_json as _http_json,
33
+ http_text as _shared_http_text,
34
+ )
29
35
 
30
36
  logger = logging.getLogger("unified_search.engines")
31
37
 
32
- _UA = "argo-search/2.4 (unified-search@local)"
33
-
34
- # 结构字符保留集:既有 %XX 编码、协议/路径/参数分隔符不重复转义
35
- _URL_SAFE = "/:?&=%,._~#+-"
36
-
37
38
 
38
- def _encode_url(url: str) -> str:
39
- """URL 非 ASCII 安全编码:中文查询(如 open_meteo geocode name=北京)
40
- 直接拼接会让 urllib 报 ascii 编码错误;已有 %XX 与结构字符不动。"""
41
- return urllib.parse.quote(url, safe=_URL_SAFE)
42
-
43
-
44
- # 地理编码类查询的自然语言噪声:open_meteo 的 geocoding 只吃地名,
45
- # 「今日北京天气」「北京今天多少度」这类完整问句会让 name= 带上时间词与
46
- # 疑问词,上游 0 候选 → 引擎静默返回空(wx.py / weather_cn 各有一份同型
47
- # 正则,漏掉任一处该查询在对应源就全军覆没)。
48
- # 只剥「查询表达」不碰地名本身:坐标串(lat,lon)、纯地名原样通过。
49
- _GEO_COORD_RE = re.compile(r"-?\d+(?:\.\d+)?\s*,\s*-?\d+(?:\.\d+)?")
50
- _GEO_NOISE_RE = re.compile(
51
- r"(天气|气温|温度|多少度|预报|怎么样|如何|下雨|降水|雪|晴|阴|"
52
- r"今[天日晚]|明[天日晚]|后[天日]|昨[天日]|现在|实时|当前|查询|"
53
- r"的|了|呢|吗|\?|?|,|,|。|\s)+",
39
+ # 天气查询的地名/跨度解析(未来N天)与 Open-Meteo 构建器已拆至
40
+ # engines_builders_weather.py(2026-11-11 拆分,本文件越过 1000 行硬上限)。
41
+ # 此处保留同名再导出,既有 `from engines_builders_intl import _geo_core`
42
+ # 的调用面(tests/plan.py/batch_probe.py)不受影响。
43
+ from engines_builders_weather import ( # noqa: E402
44
+ forecast_span as _forecast_span,
45
+ geo_core as _geo_core,
46
+ build_open_meteo_engine as _build_open_meteo_engine,
54
47
  )
55
48
 
56
49
 
57
- def _geo_core(query: str) -> str:
58
- """剥掉天气问句的时间/疑问词,留地名;空则回退原查询(不猜)。"""
59
- raw = (query or "").strip()
60
- # 坐标串(lat,lon)不是问句,原样透传——剥了逗号反而毁掉它
61
- if _GEO_COORD_RE.fullmatch(raw):
62
- return raw
63
- q = _GEO_NOISE_RE.sub(" ", raw).strip()
64
- return q or raw
65
-
66
-
67
- def _http_json(url: str, timeout: float, engine: str = "") -> Any:
68
- req = urllib.request.Request(_encode_url(url), headers={"User-Agent": _UA, "Accept-Encoding": "gzip"})
69
- with http_open(req, timeout=timeout, engine=engine) as resp:
70
- raw = resp.read()
71
- if resp.headers.get("Content-Encoding") == "gzip":
72
- import gzip
73
- raw = gzip.decompress(raw)
74
- return json.loads(raw.decode("utf-8", "replace"))
75
-
76
-
77
50
  def _http_text(url: str, timeout: float, engine: str = "") -> str:
78
- req = urllib.request.Request(_encode_url(url), headers={"User-Agent": _UA})
79
- with http_open(req, timeout=timeout, engine=engine) as resp:
80
- return resp.read().decode("utf-8", "replace")
81
-
82
-
83
- # ── CiNii Research ────────────────────────────────────────────────────────────
84
-
85
- def _build_cnii_engine(spec: dict[str, Any]) -> Any:
86
- """CiNii Research 学术总库(cir.nii.ac.jp,OpenSearch JSON-LD,免认证)。"""
87
- timeout = spec.get("timeout", 12)
88
-
89
- @safe_search
90
- def _engine(query: str, n: int = 5, _timeout: float | None = None, **kwargs) -> list[dict[str, Any]]:
91
- to = _timeout or timeout
92
- url = f"https://cir.nii.ac.jp/opensearch/all?q={urllib.parse.quote(query)}&format=json&count={min(n, 10)}"
93
- try:
94
- data = _http_json(url, to, engine=spec.get("_name", ""))
95
- except Exception as e:
96
- logger.warning(f"CiNii 失败: {e}")
97
- return []
98
- results = []
99
- for _rk, it in enumerate((data.get("items") or [])[:n]):
100
- if not isinstance(it, dict):
101
- continue
102
- title = it.get("title", "")
103
- link = it.get("link")
104
- url_ = link.get("@id", "") if isinstance(link, dict) else str(link or "")
105
- creators = it.get("dc:creator") or []
106
- if isinstance(creators, str):
107
- creators = [creators]
108
- year = it.get("prism:publicationDate", "")
109
- parts = [p for p in (", ".join(str(c) for c in creators[:3]), str(year)) if p]
110
- if not title and not url_:
111
- continue
112
- results.append({
113
- "title": str(title)[:200],
114
- "url": url_,
115
- "snippet": (" · ".join(parts) + " · " + str(it.get("description", "")))[:300],
116
- "source": "cnii",
117
- "score": rank_score(0.7, _rk),
118
- })
119
- return results
120
- return _engine
51
+ return _shared_http_text(url, timeout, engine=engine, opener=http_open)
121
52
 
122
53
 
123
54
  # ── NDL Search(OpenSearch RSS)───────────────────────────────────────────────
@@ -318,249 +249,6 @@ def _build_dnb_engine(spec: dict[str, Any]) -> Any:
318
249
  return _engine
319
250
 
320
251
 
321
- # ── DOAJ 开放获取期刊 ─────────────────────────────────────────────────────────
322
-
323
- def _build_doaj_engine(spec: dict[str, Any]) -> Any:
324
- """DOAJ 开放获取期刊全球总库(doaj.org/api,bibjson 嵌套结构)。"""
325
- timeout = spec.get("timeout", 12)
326
-
327
- @safe_search
328
- def _engine(query: str, n: int = 5, _timeout: float | None = None, **kwargs) -> list[dict[str, Any]]:
329
- to = _timeout or timeout
330
- url = f"https://doaj.org/api/search/articles/{urllib.parse.quote(query)}?pageSize={min(n, 10)}"
331
- try:
332
- data = _http_json(url, to, engine=spec.get("_name", ""))
333
- except Exception as e:
334
- logger.warning(f"DOAJ 失败: {e}")
335
- return []
336
- results = []
337
- for _rk5, r in enumerate((data.get("results") or [])[:n]):
338
- bib = r.get("bibjson") or {}
339
- title = bib.get("title", "")
340
- # link 是 [{url, type}] 数组,取 fulltext/doi 优先
341
- link = ""
342
- for lk in (bib.get("link") or []):
343
- if isinstance(lk, dict):
344
- u = lk.get("url", "")
345
- if u and (lk.get("type") in ("fulltext", "doi") or not link):
346
- link = u
347
- authors = bib.get("author") or []
348
- if isinstance(authors, list):
349
- names = [a.get("name", "") for a in authors[:3] if isinstance(a, dict)]
350
- else:
351
- names = []
352
- year = bib.get("year", "")
353
- parts = [p for p in (", ".join(names), str(year), bib.get("journal", {}).get("title", "") if isinstance(bib.get("journal"), dict) else "") if p]
354
- if not title and not link:
355
- continue
356
- results.append({
357
- "title": str(title)[:200],
358
- "url": link,
359
- "snippet": (" · ".join(parts) + " · " + str(bib.get("abstract", "")))[:300],
360
- "source": "doaj",
361
- "score": rank_score(0.7, _rk5),
362
- })
363
- return results
364
- return _engine
365
-
366
-
367
- # ── Europeana 欧洲文化遗产 ────────────────────────────────────────────────────
368
-
369
- def _build_europeana_engine(spec: dict[str, Any]) -> Any:
370
- """Europeana 欧洲文化遗产聚合(api.europeana.eu,官方公开 demo key api2demo)。"""
371
- timeout = spec.get("timeout", 12)
372
-
373
- @safe_search
374
- def _engine(query: str, n: int = 5, _timeout: float | None = None, **kwargs) -> list[dict[str, Any]]:
375
- to = _timeout or timeout
376
- url = (f"https://api.europeana.eu/record/v2/search.json?wskey=api2demo"
377
- f"&query={urllib.parse.quote(query)}&rows={min(n, 10)}")
378
- try:
379
- data = _http_json(url, to, engine=spec.get("_name", ""))
380
- except Exception as e:
381
- logger.warning(f"Europeana 失败: {e}")
382
- return []
383
- results = []
384
- for _rk6, it in enumerate((data.get("items") or [])[:n]):
385
- if not isinstance(it, dict):
386
- continue
387
- title = it.get("title")
388
- if isinstance(title, list):
389
- title = title[0] if title else ""
390
- link = it.get("link", "")
391
- provider = it.get("dataProvider")
392
- if isinstance(provider, list):
393
- provider = provider[0] if provider else ""
394
- if not title and not link:
395
- continue
396
- results.append({
397
- "title": str(title)[:200],
398
- "url": link,
399
- "snippet": (f"provider: {provider}" if provider else "")[:300],
400
- "source": "europeana",
401
- "score": rank_score(0.7, _rk6),
402
- })
403
- return results
404
- return _engine
405
-
406
-
407
- # ── HAL 法国科研开放仓储 ──────────────────────────────────────────────────────
408
-
409
- def _build_hal_engine(spec: dict[str, Any]) -> Any:
410
- """HAL 法国全国科研机构开放仓储(api.archives-ouvertes.fr Solr JSON)。"""
411
- timeout = spec.get("timeout", 12)
412
-
413
- @safe_search
414
- def _engine(query: str, n: int = 5, _timeout: float | None = None, **kwargs) -> list[dict[str, Any]]:
415
- to = _timeout or timeout
416
- url = ("https://api.archives-ouvertes.fr/search/?wt=json"
417
- f"&q={urllib.parse.quote(query)}&rows={min(n, 10)}"
418
- "&fl=title_s,uri_s,abstract_s,authFullName_s,producedDate_s")
419
- try:
420
- data = _http_json(url, to, engine=spec.get("_name", ""))
421
- except Exception as e:
422
- logger.warning(f"HAL 失败: {e}")
423
- return []
424
- results = []
425
- for _rk7, doc in enumerate((data.get("response", {}).get("docs") or [])[:n]):
426
- title = doc.get("title_s")
427
- if isinstance(title, list):
428
- title = title[0] if title else ""
429
- link = doc.get("uri_s", "")
430
- authors = doc.get("authFullName_s") or []
431
- date = doc.get("producedDate_s") or ""
432
- parts = [p for p in (", ".join(str(a) for a in authors[:3]), str(date)) if p]
433
- if not title and not link:
434
- continue
435
- results.append({
436
- "title": str(title)[:200],
437
- "url": link,
438
- "snippet": (" · ".join(parts) + " · " + str(doc.get("abstract_s", "")))[:300],
439
- "source": "hal",
440
- "score": rank_score(0.7, _rk7),
441
- })
442
- return results
443
- return _engine
444
-
445
-
446
- # ── EU Open Data Portal ───────────────────────────────────────────────────────
447
-
448
- def _build_eu_opendata_engine(spec: dict[str, Any]) -> Any:
449
- """EU Open Data Portal(data.europa.eu/api/hub,24 语言元数据)。"""
450
- timeout = spec.get("timeout", 12)
451
-
452
- @safe_search
453
- def _engine(query: str, n: int = 5, _timeout: float | None = None, **kwargs) -> list[dict[str, Any]]:
454
- to = _timeout or timeout
455
- url = f"https://data.europa.eu/api/hub/search/search?q={urllib.parse.quote(query)}&pageSize={min(n, 10)}"
456
- try:
457
- data = _http_json(url, to, engine=spec.get("_name", ""))
458
- except Exception as e:
459
- logger.warning(f"EU ODP 失败: {e}")
460
- return []
461
- results = []
462
- for _rk8, it in enumerate((data.get("result", {}).get("results") or [])[:n]):
463
- if not isinstance(it, dict):
464
- continue
465
- # title 是 {语言code: 标题} 映射;优先 en/zh,否则取首个
466
- title = ""
467
- tl = it.get("title") or {}
468
- if isinstance(tl, dict):
469
- for lang in ("en", "zh", "fr", "de"):
470
- if tl.get(lang):
471
- title = tl[lang]
472
- break
473
- if not title and tl:
474
- title = next(iter(tl.values()))
475
- url_ = (it.get("landing_page") or it.get("resource")
476
- or it.get("id") or "")
477
- if isinstance(url_, list):
478
- # landing_page 是 [{resource: url}] 数组
479
- url_ = url_[0].get("resource", "") if url_ and isinstance(url_[0], dict) else ""
480
- if not title and not url_:
481
- continue
482
- results.append({
483
- "title": str(title)[:200],
484
- "url": str(url_),
485
- "snippet": "",
486
- "source": "eu_opendata",
487
- "score": rank_score(0.7, _rk8),
488
- })
489
- return results
490
- return _engine
491
-
492
-
493
- # ── Open-Meteo 全球天气 ───────────────────────────────────────────────────────
494
-
495
- def _build_open_meteo_engine(spec: dict[str, Any]) -> Any:
496
- """Open-Meteo 全球天气(geocoding + forecast,免认证)。
497
-
498
- 查询词视为城市名/地名,先 geocode 取坐标再取当前天气。
499
- """
500
- timeout = spec.get("timeout", 12)
501
-
502
- @safe_search
503
- def _engine(query: str, n: int = 5, _timeout: float | None = None, **kwargs) -> list[dict[str, Any]]:
504
- to = _timeout or timeout
505
- # geocoding 只吃地名:完整天气问句(「今日北京天气」)先剥时间/疑问词,
506
- # 否则上游 0 候选、引擎静默返回空
507
- place_q = _geo_core(query)
508
- try:
509
- geo = _http_json(
510
- f"https://geocoding-api.open-meteo.com/v1/search?name={urllib.parse.quote(place_q)}&count=3&language=zh",
511
- to, engine=spec.get("_name", ""))
512
- except Exception as e:
513
- logger.warning(f"Open-Meteo geocode 失败: {e}")
514
- return []
515
- results = []
516
- places = [p for p in (geo.get("results") or [])[:n]
517
- if p.get("latitude") is not None and p.get("longitude") is not None]
518
- if not places:
519
- return results
520
-
521
- def _fetch_place(item: tuple[int, dict[str, Any]]):
522
- """单个 place 的 forecast;失败返回 None(与串行版逐个 except 一致)。"""
523
- _rk9, place = item
524
- lat, lon = place["latitude"], place["longitude"]
525
- try:
526
- wx = _http_json(
527
- f"https://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lon}&current_weather=true",
528
- to, engine=spec.get("_name", ""))
529
- except Exception:
530
- return None
531
- cw = wx.get("current_weather") or {}
532
- name = place.get("name", "")
533
- country = place.get("country", "")
534
- temp = cw.get("temperature")
535
- windspeed = cw.get("windspeed")
536
- wcode = cw.get("weathercode")
537
- wmo = {0: "晴", 1: "基本晴", 2: "多云", 3: "阴", 45: "雾", 48: "雾凇",
538
- 51: "毛毛雨", 61: "小雨", 63: "中雨", 65: "大雨", 71: "小雪",
539
- 73: "中雪", 75: "大雪", 80: "阵雨", 95: "雷暴"}.get(wcode, f"code{wcode}")
540
- return (_rk9, {
541
- "title": f"{name} · {country} 天气",
542
- "url": f"https://open-meteo.com/en/docs?latitude={lat}&longitude={lon}",
543
- "snippet": (f"当前 {temp}°C · {wmo} · 风速 {windspeed}km/h"
544
- if temp is not None else "暂无数据")[:300],
545
- "source": "open_meteo",
546
- "score": rank_score(0.7, _rk9),
547
- })
548
-
549
- # 多 place 的 forecast 并行(2026-09-29):串行版在 geocode 返回 3 个
550
- # 候选时墙钟 = geocode + 3×forecast(实测 9.28s 恒定);有界并发后
551
- # = geocode + max(forecast)(实测 3.9-5.1s)。总上限 to+2s ≤ 串行
552
- # 最坏 n×to;daemon 线程 + 轮询,卡住的 HTTP 读拖不垮止损
553
- # (bounded_run 文档依据;与 wx.py:252「同坐标多端点并行」同哲学)。
554
- finished, _unfinished = run_bounded(
555
- list(enumerate(places)), _fetch_place,
556
- wait_s=float(to) + 2.0, max_workers=3)
557
- # 保序:按候选序号重排,与串行版输出逐位一致(rank_score 依赖 _rk9)
558
- results = [r for _rk, r in sorted(
559
- (v for _i, v in finished if isinstance(v, tuple)),
560
- key=lambda t: t[0])]
561
- return results
562
- return _engine
563
-
564
252
 
565
253
  # ── SearchMySite 小型个人站索引(HTML)───────────────────────────────────────
566
254
 
@@ -740,122 +428,6 @@ def _build_electricity_maps_engine(spec: dict[str, Any]) -> Any:
740
428
  return _engine
741
429
 
742
430
 
743
- # ── USDA FoodData Central 营养成分 ────────────────────────────────────────────
744
-
745
- def _build_usda_engine(spec: dict[str, Any]) -> Any:
746
- """USDA FoodData Central 营养成分(api.nal.usda.gov,官方 DEMO_KEY)。"""
747
- timeout = spec.get("timeout", 12)
748
-
749
- @safe_search
750
- def _engine(query: str, n: int = 5, _timeout: float | None = None, **kwargs) -> list[dict[str, Any]]:
751
- to = _timeout or timeout
752
- url = (f"https://api.nal.usda.gov/fdc/v1/foods/search?api_key=DEMO_KEY"
753
- f"&query={urllib.parse.quote(query)}&pageSize={min(n, 10)}")
754
- try:
755
- data = _http_json(url, to, engine=spec.get("_name", ""))
756
- except Exception as e:
757
- logger.warning(f"USDA 失败: {e}")
758
- return []
759
- results = []
760
- for _rk14, food in enumerate((data.get("foods") or [])[:n]):
761
- if not isinstance(food, dict):
762
- continue
763
- desc = food.get("description", "")
764
- fdc = food.get("fdcId", "")
765
- brand = food.get("brandOwner") or ""
766
- parts = [p for p in (food.get("foodCategory", ""), brand) if p]
767
- if not desc:
768
- continue
769
- results.append({
770
- "title": desc[:200],
771
- "url": f"https://fdc.nal.usda.gov/food-details/{fdc}/nutrients" if fdc else "",
772
- "snippet": (" · ".join(parts) + f" · FDC {fdc}")[:300] if fdc else " · ".join(parts)[:300],
773
- "source": "usda",
774
- "score": rank_score(0.7, _rk14),
775
- })
776
- return results
777
- return _engine
778
-
779
-
780
- # ── Tatoeba 双语例句 ──────────────────────────────────────────────────────────
781
-
782
- def _build_tatoeba_engine(spec: dict[str, Any]) -> Any:
783
- """Tatoeba 多语言例句库(tatoeba.org/api_v0,400+ 语言对)。"""
784
- timeout = spec.get("timeout", 12)
785
-
786
- @safe_search
787
- def _engine(query: str, n: int = 5, _timeout: float | None = None, **kwargs) -> list[dict[str, Any]]:
788
- to = _timeout or timeout
789
- url = (f"https://tatoeba.org/en/api_v0/search?query={urllib.parse.quote(query)}"
790
- f"&limit={min(n, 10)}")
791
- try:
792
- data = _http_json(url, to, engine=spec.get("_name", ""))
793
- except Exception as e:
794
- logger.warning(f"Tatoeba 失败: {e}")
795
- return []
796
- results = []
797
- sentences = data.get("results")
798
- if isinstance(sentences, dict):
799
- sentences = sentences.get("Sentences") or []
800
- for _rk15, s in enumerate((sentences or [])[:n]):
801
- if not isinstance(s, dict):
802
- continue
803
- text = s.get("text", "")
804
- lang = s.get("lang", "")
805
- trans = s.get("translations") or []
806
- t_texts = []
807
- # translations 是 list of lists(每层一个目标语言数组)
808
- for t in trans[:3]:
809
- arr = t if isinstance(t, list) else []
810
- t_texts.extend(str(x.get("text", "")) for x in arr[:2] if isinstance(x, dict))
811
- snippet = " ⇄ ".join(t for t in t_texts if t)[:200] or f"({lang})"
812
- if not text:
813
- continue
814
- results.append({
815
- "title": text[:200],
816
- "url": f"https://tatoeba.org/en/sentences/show/{s.get('id', '')}" if s.get("id") else "",
817
- "snippet": snippet,
818
- "source": "tatoeba",
819
- "score": rank_score(0.7, _rk15),
820
- })
821
- return results
822
- return _engine
823
-
824
-
825
- # ── Figshare 科研数据集 ───────────────────────────────────────────────────────
826
-
827
- def _build_figshare_engine(spec: dict[str, Any]) -> Any:
828
- """Figshare 科研数据集检索(api.figshare.com/v2/articles)。"""
829
- timeout = spec.get("timeout", 12)
830
-
831
- @safe_search
832
- def _engine(query: str, n: int = 5, _timeout: float | None = None, **kwargs) -> list[dict[str, Any]]:
833
- to = _timeout or timeout
834
- url = (f"https://api.figshare.com/v2/articles?search_for={urllib.parse.quote(query)}"
835
- f"&page_size={min(n, 10)}")
836
- try:
837
- data = _http_json(url, to, engine=spec.get("_name", ""))
838
- except Exception as e:
839
- logger.warning(f"Figshare 失败: {e}")
840
- return []
841
- results = []
842
- for _rk16, art in enumerate((data if isinstance(data, list) else [])[:n]):
843
- if not isinstance(art, dict):
844
- continue
845
- title = art.get("title", "")
846
- if not title:
847
- continue
848
- results.append({
849
- "title": str(title)[:200],
850
- "url": art.get("url_public_api") or art.get("url_public_html") or "",
851
- "snippet": f"DOI: {art.get('doi', '')}"[:300] if art.get("doi") else "",
852
- "source": "figshare",
853
- "score": rank_score(0.7, _rk16),
854
- })
855
- return results
856
- return _engine
857
-
858
-
859
431
  # ── 腾讯 K 线(前复权日 K)────────────────────────────────────────────────────
860
432
 
861
433
  def _resolve_tencent_symbol(q: str, to: float, headers: dict, engine: str = "") -> str:
@@ -26,23 +26,9 @@ from engine_env import env_flag, get_env
26
26
  from engines_base import finalize_image_fields, http_open, rank_score, safe_search
27
27
 
28
28
 
29
- class _LazyLogger:
30
- """延迟创建 logger,避免 import logging 的重量级 import 链。"""
29
+ from engines_http import lazy_logger
31
30
 
32
- _logger = None
33
-
34
- def __getattr__(self, name: str):
35
- if _LazyLogger._logger is None:
36
- import logging
37
-
38
- _LazyLogger._logger = logging.getLogger("unified_search.engines")
39
- if not _LazyLogger._logger.handlers:
40
- _LazyLogger._logger.setLevel(logging.WARNING)
41
- _LazyLogger._logger.addHandler(logging.StreamHandler(sys.stderr))
42
- return getattr(_LazyLogger._logger, name)
43
-
44
-
45
- logger = _LazyLogger()
31
+ logger = lazy_logger()
46
32
 
47
33
  _WEB_API = "https://www.pixiv.net/ajax/search/artworks"
48
34
  _APP_API = "https://app-api.pixiv.net/v1/search/illust"
@@ -23,49 +23,6 @@ from engines_base import (
23
23
 
24
24
  logger = logging.getLogger("unified_search.engines")
25
25
 
26
- # ── ClinicalTrials.gov v2 ────────────────────────────────────────────────────
27
-
28
- def _build_clinicaltrials_engine(spec: dict[str, Any]) -> Any:
29
- """ClinicalTrials.gov API v2 试验检索(免认证)。"""
30
- timeout = spec.get("timeout", 12)
31
-
32
- @safe_search
33
- def _engine(query: str, n: int = 5, _timeout: float | None = None, **kwargs) -> list[dict[str, Any]]:
34
- import urllib.parse as up
35
- q = " ".join(re.findall(r"[A-Za-z0-9][A-Za-z0-9._+-]*", query))
36
- if not re.search(r"[A-Za-z]{2,}", q):
37
- return []
38
- to = _timeout or timeout
39
- url = "https://clinicaltrials.gov/api/v2/studies?" + up.urlencode({
40
- "query.term": q, "pageSize": min(n, 20), "format": "json"})
41
- try:
42
- with http_open(urllib.request.Request(
43
- url, headers={"User-Agent": "argo-search/2.5", "Accept": "application/json"}), timeout=to, engine=spec.get("_name", "")) as resp:
44
- data = json.loads(resp.read().decode("utf-8", "replace"))
45
- except Exception as e:
46
- logger.warning(f"clinicaltrials 失败: {e}")
47
- return []
48
- results = []
49
- for _rk5, st in enumerate((data.get("studies") or [])[:n]):
50
- ps = st.get("protocolSection") or {}
51
- ident = ps.get("identificationModule") or {}
52
- desc = ps.get("descriptionModule") or {}
53
- status = (ps.get("statusModule") or {}).get("overallStatus") or ""
54
- nct = ident.get("nctId") or ""
55
- title = ident.get("briefTitle") or ident.get("officialTitle") or nct
56
- summary = desc.get("briefSummary") or status
57
- if not title and not nct:
58
- continue
59
- results.append({
60
- "title": str(title)[:200],
61
- "url": f"https://clinicaltrials.gov/study/{nct}" if nct else "",
62
- "snippet": str(summary).replace("\n", " ")[:300],
63
- "source": "clinicaltrials",
64
- "score": rank_score(0.85, _rk5),
65
- })
66
- return results
67
- return _engine
68
-
69
26
 
70
27
  # ── openFDA 药品标签 ─────────────────────────────────────────────────────────
71
28
 
@@ -653,48 +610,6 @@ def _build_usgs_engine(spec: dict[str, Any]) -> Any:
653
610
  return _engine
654
611
 
655
612
 
656
- # ── NASA CMR 地球科学数据目录引擎 ────────────────────────────────────────────
657
-
658
- _CMR_API = "https://cmr.earthdata.nasa.gov/search/collections.json"
659
-
660
-
661
- def _build_nasa_cmr_engine(spec: dict[str, Any]) -> Any:
662
- """NASA CMR 地球科学数据目录检索(cmr.earthdata.nasa.gov,免认证)。
663
-
664
- MODIS/卫星/遥感等关键词 → 数据集集合(含概念 ID,链接 Earthdata Search)。
665
- """
666
- timeout = spec.get("timeout", 12)
667
- _HEADERS = {"User-Agent": "argo-search/2.6 (unified-search@local)", "Accept": "application/json"}
668
-
669
- @safe_search
670
- def _engine(query: str, n: int = 5, _timeout: float | None = None, **kwargs) -> list[dict[str, Any]]:
671
- q = _ascii_tokens(query)
672
- if not q:
673
- return []
674
- to = _timeout or timeout
675
- url = _CMR_API + "?" + urllib.parse.urlencode({"keyword": q, "page_size": min(n, 10)})
676
- try:
677
- with http_open(urllib.request.Request(url, headers=_HEADERS), timeout=to, engine=spec.get("_name", "")) as resp:
678
- data = json.loads(resp.read().decode("utf-8", "replace"))
679
- except Exception as e:
680
- logger.warning(f"NASA CMR 失败: {e}")
681
- return []
682
- results = []
683
- for _rk16, x in enumerate(((data.get("feed") or {}).get("entry") or [])[:n]):
684
- title = x.get("title") or q
685
- cid = x.get("id") or ""
686
- summary = (x.get("summary") or "")[:200]
687
- results.append({
688
- "title": title,
689
- "url": f"https://search.earthdata.nasa.gov/search/granules?p={cid}" if cid else "",
690
- "snippet": summary[:300],
691
- "source": "nasa_cmr",
692
- "score": rank_score(0.8, _rk16),
693
- })
694
- return results
695
- return _engine
696
-
697
-
698
613
  # ── bioRxiv / medRxiv 预印本引擎 ─────────────────────────────────────────────
699
614
 
700
615
  # DOI 提取:10. 开头的标准 DOI(bioRxiv DOI 形态 10.1101/2024.01.02.123456)
@@ -27,21 +27,9 @@ from engines_base import safe_search, http_open, mcp_error_of as _mcp_error_of
27
27
  from engine_env import get_env
28
28
 
29
29
 
30
- class _LazyLogger:
31
- """延迟创建 logger,避免 import logging 的重量级 import 链(traceback→dataclasses→inspect)。"""
32
- _logger = None
30
+ from engines_http import lazy_logger
33
31
 
34
- def __getattr__(self, name: str):
35
- if _LazyLogger._logger is None:
36
- import logging
37
- _LazyLogger._logger = logging.getLogger("unified_search.engines")
38
- if not _LazyLogger._logger.handlers:
39
- _LazyLogger._logger.setLevel(logging.WARNING)
40
- _LazyLogger._logger.addHandler(logging.StreamHandler(sys.stderr))
41
- return getattr(_LazyLogger._logger, name)
42
-
43
-
44
- logger = _LazyLogger()
32
+ logger = lazy_logger()
45
33
 
46
34
  # ── Parallel 搜索(api.parallel.ai)────────────────────────────────────────────
47
35
 
@@ -175,6 +163,11 @@ def _build_parallel_free_engine(spec: dict[str, Any]) -> Any:
175
163
  except ImportError:
176
164
  return []
177
165
  if resp.get("status", 0) >= 400 or not resp.get("text"):
166
+ try:
167
+ from engines_base import _note_http_failure
168
+ _note_http_failure("parallel_free", resp.get("status") or 0, resp.get("text") or resp.get("error", ""))
169
+ except Exception:
170
+ pass
178
171
  return []
179
172
  try:
180
173
  data = json.loads(resp["text"])