argo-search 2.15.0 → 2.16.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 +1 -1
- package/README.es.md +27 -5
- package/README.ja.md +27 -5
- package/README.ko.md +27 -5
- package/README.md +68 -19
- package/README.zh.md +68 -19
- package/SKILL.md +7 -7
- package/assets/readme/counts.json +1 -1
- package/backends/domain_profiles.json +107 -6
- package/backends/engine_registry.yaml +15 -2
- package/backends/quota_profiles.json +13 -3
- package/bin/argo +3 -0
- package/config.yaml +16 -0
- package/docs/CHANGELOG.md +15 -0
- package/docs/ENGINE_CATALOG.md +11 -10
- package/docs/MCP_SETUP.md +9 -0
- package/docs/RELEASE_NOTES_v2.16.0.md +58 -0
- package/engines/specs/archive_org.yaml +1 -1
- package/engines/specs/carbon_intensity.yaml +1 -1
- package/engines/specs/crates.yaml +1 -1
- package/engines/specs/crossref.yaml +4 -2
- package/engines/specs/crt_sh.yaml +1 -1
- package/engines/specs/dblp.yaml +1 -1
- package/engines/specs/devto.yaml +1 -1
- package/engines/specs/docker_hub.yaml +1 -1
- package/engines/specs/europepmc.yaml +1 -1
- package/engines/specs/fxtwitter.yaml +1 -1
- package/engines/specs/gbfs_nyc.yaml +1 -1
- package/engines/specs/gleif.yaml +1 -1
- package/engines/specs/gov_regulations.yaml +1 -1
- package/engines/specs/hf_datasets.yaml +1 -1
- package/engines/specs/huggingface.yaml +1 -1
- package/engines/specs/keenable.yaml +7 -1
- package/engines/specs/linux_do.yaml +63 -0
- package/engines/specs/local_crossref.yaml +3 -1
- package/engines/specs/local_github.yaml +1 -1
- package/engines/specs/local_npm.yaml +6 -0
- package/engines/specs/local_openstreetmap.yaml +1 -1
- package/engines/specs/maven.yaml +1 -1
- package/engines/specs/mdn.yaml +1 -1
- package/engines/specs/musicbrainz.yaml +1 -1
- package/engines/specs/nasa_images.yaml +1 -1
- package/engines/specs/nhtsa_vpic.yaml +6 -3
- package/engines/specs/npm.yaml +1 -1
- package/engines/specs/nuget.yaml +1 -1
- package/engines/specs/nvd.yaml +1 -1
- package/engines/specs/openalex.yaml +4 -2
- package/engines/specs/openreview.yaml +1 -1
- package/engines/specs/polymarket.yaml +1 -1
- package/engines/specs/sec_edgar.yaml +1 -1
- package/engines/specs/steam.yaml +1 -1
- package/engines/specs/vam.yaml +1 -1
- package/engines/specs/wikidata.yaml +1 -1
- package/engines/specs/wikipedia.yaml +1 -1
- package/engines/specs/zhihu_hot_app.yaml +1 -1
- package/package.json +2 -1
- package/packages/dsh-plugin/dsh/client.js +14 -13
- package/packages/dsh-plugin/dsh/index.js +6 -0
- package/packages/dsh-plugin/dsh/runner.js +1 -1
- package/packages/dsh-plugin/dsh/workbench-client.js +796 -0
- package/packages/dsh-plugin/dsh/workbench-md.js +386 -0
- package/packages/dsh-plugin/dsh/workbench-suggestions.js +148 -0
- package/packages/dsh-plugin/dsh/workbench.js +966 -0
- package/packages/dsh-plugin/icon.svg +23 -0
- package/packages/dsh-plugin/package.json +3 -1
- package/packages/dsh-plugin/test/workbench.test.js +92 -0
- package/scripts/argo_paths.py +2 -2
- package/scripts/badcase_ledger.py +9 -0
- package/scripts/cache.py +1 -1
- package/scripts/circuit_breaker.py +16 -3
- package/scripts/config_cache.py +19 -7
- package/scripts/daemon.py +5 -0
- package/scripts/engine_dispatch.py +5 -2
- package/scripts/engine_env.py +13 -4
- package/scripts/engines_base.py +24 -3
- package/scripts/engines_builders_archive.py +4 -3
- package/scripts/engines_builders_batch11.py +2 -1
- package/scripts/engines_builders_batch13.py +4 -3
- package/scripts/engines_builders_batch14.py +2 -1
- package/scripts/engines_builders_batch15.py +2 -1
- package/scripts/engines_builders_batch9.py +2 -2
- package/scripts/engines_builders_cn.py +7 -7
- package/scripts/engines_builders_data.py +12 -11
- package/scripts/engines_builders_data_macro.py +5 -4
- package/scripts/engines_builders_dsh.py +2 -1
- package/scripts/engines_builders_feeds.py +34 -19
- package/scripts/engines_builders_finance.py +2 -1
- package/scripts/engines_builders_intl.py +3 -2
- package/scripts/engines_builders_media.py +59 -12
- package/scripts/engines_builders_science.py +8 -7
- package/scripts/engines_builders_skill.py +2 -1
- package/scripts/engines_builders_tech.py +3 -3
- package/scripts/engines_builders_weather.py +9 -4
- package/scripts/engines_http.py +50 -1
- package/scripts/engines_mcp.py +28 -6
- package/scripts/evidence_loop.py +15 -1
- package/scripts/extend_route_labels.py +6 -0
- package/scripts/fetch_jina.py +98 -0
- package/scripts/fetch_v3.py +52 -93
- package/scripts/image_vision/vision_probe +0 -0
- package/scripts/install.sh +2 -0
- package/scripts/matrix_search_eval.py +8 -10
- package/scripts/mcp_transport.py +10 -5
- package/scripts/numeric_verify.py +3 -2
- package/scripts/output_transparency.py +3 -0
- package/scripts/quota.py +30 -29
- package/scripts/recovery.py +19 -16
- package/scripts/recovery_runner.py +29 -10
- package/scripts/redskill/redskill_engine.py +2 -1
- package/scripts/route.py +8 -0
- package/scripts/route_combo.py +11 -2
- package/scripts/route_policy.py +1 -1
- package/scripts/search_attribution.py +20 -0
- package/scripts/search_entry.py +27 -0
- package/scripts/search_output.py +18 -7
- package/scripts/search_pipeline.py +3 -3
- package/scripts/semantic_evidence.py +20 -11
- package/scripts/serp_guard.py +13 -1
- package/scripts/settings_page.py +1 -0
- package/scripts/single_flight.py +1 -1
- package/scripts/social_engines/hackernews_engine.py +2 -1
- package/scripts/social_engines/reddit_engine.py +2 -1
- package/scripts/social_engines/zhihu_engine.py +2 -1
- package/scripts/source_audit.py +42 -7
- package/scripts/usage_log.py +24 -9
- package/scripts/watch.py +3 -3
- package/scripts/zhihu_quota.py +2 -1
- package/sub-skills/argo-wide-research/SKILL.md +7 -5
- package/sub-skills/ego-search/{SKILL.md → README.md} +15 -47
- package/sub-skills/ego-search/scripts/ego_search.py +13 -4
- package/sub-skills/js-run/{SKILL.md → README.md} +3 -20
- package/sub-skills/local-search/{SKILL.md → README.md} +3 -8
- package/sub-skills/local-search/engine_registry.py +32 -7
- package/sub-skills/local-seek/SKILL.md +20 -22
|
@@ -17,6 +17,7 @@ from typing import Any
|
|
|
17
17
|
|
|
18
18
|
from cjk_tokens import cjk_term_grams, signal_tokens
|
|
19
19
|
from engine_env import get_env
|
|
20
|
+
from engines_http import UA
|
|
20
21
|
from engines_base import (
|
|
21
22
|
rank_score,
|
|
22
23
|
safe_search, _run, _resolve, _get_path, _coerce_field, _detect_anti_bot,
|
|
@@ -42,7 +43,7 @@ def _build_open_library_engine(spec: dict[str, Any]) -> Any:
|
|
|
42
43
|
})
|
|
43
44
|
try:
|
|
44
45
|
with http_open(urllib.request.Request(
|
|
45
|
-
url, headers={"User-Agent":
|
|
46
|
+
url, headers={"User-Agent": UA}), timeout=to, engine=spec.get("_name", "")) as resp:
|
|
46
47
|
data = json.loads(resp.read().decode("utf-8", "replace"))
|
|
47
48
|
except Exception as e:
|
|
48
49
|
logger.warning(f"Open Library 失败: {e}")
|
|
@@ -96,7 +97,7 @@ def _build_weread_engine(spec: dict[str, Any]) -> Any:
|
|
|
96
97
|
headers={
|
|
97
98
|
"Authorization": f"Bearer {key}",
|
|
98
99
|
"Content-Type": "application/json",
|
|
99
|
-
"User-Agent":
|
|
100
|
+
"User-Agent": UA,
|
|
100
101
|
},
|
|
101
102
|
)
|
|
102
103
|
try:
|
|
@@ -225,7 +226,7 @@ def _build_free_dictionary_engine(spec: dict[str, Any]) -> Any:
|
|
|
225
226
|
url = f"https://api.dictionaryapi.dev/api/v2/entries/en/{up.quote(word)}"
|
|
226
227
|
try:
|
|
227
228
|
with http_open(urllib.request.Request(
|
|
228
|
-
url, headers={"User-Agent":
|
|
229
|
+
url, headers={"User-Agent": UA}), timeout=to, engine=spec.get("_name", "")) as resp:
|
|
229
230
|
entries = json.loads(resp.read().decode("utf-8", "replace"))
|
|
230
231
|
except Exception:
|
|
231
232
|
return []
|
|
@@ -362,7 +363,7 @@ def _build_pypi_engine(spec: dict[str, Any]) -> Any:
|
|
|
362
363
|
to = _timeout or timeout
|
|
363
364
|
results: list[dict[str, Any]] = []
|
|
364
365
|
seen: set[str] = set()
|
|
365
|
-
headers = {"User-Agent":
|
|
366
|
+
headers = {"User-Agent": UA, "Accept": "application/json"}
|
|
366
367
|
for _rk4, name in enumerate(_candidates(query)):
|
|
367
368
|
if len(results) >= n:
|
|
368
369
|
break
|
|
@@ -479,7 +480,7 @@ def _build_models_dev_engine(spec: dict[str, Any]) -> Any:
|
|
|
479
480
|
if cached is None or (now - ts) > _MODELS_DEV_TTL:
|
|
480
481
|
req = urllib.request.Request(
|
|
481
482
|
"https://models.dev/api.json",
|
|
482
|
-
headers={"User-Agent":
|
|
483
|
+
headers={"User-Agent": UA},
|
|
483
484
|
)
|
|
484
485
|
with http_open(req, timeout=to, engine=spec.get("_name", "")) as resp:
|
|
485
486
|
cached = json.loads(resp.read().decode("utf-8"))
|
|
@@ -592,7 +593,7 @@ def _build_qweather_engine(spec: dict[str, Any]) -> Any:
|
|
|
592
593
|
|
|
593
594
|
# 1) GeoAPI: 城市 → LocationID
|
|
594
595
|
geo_url = f"https://geoapi.qweather.com/v2/city/lookup?location={up.quote(city)}&key={key}"
|
|
595
|
-
req = urllib.request.Request(geo_url, headers={"User-Agent":
|
|
596
|
+
req = urllib.request.Request(geo_url, headers={"User-Agent": UA})
|
|
596
597
|
with http_open(req, timeout=to, engine=spec.get("_name", "")) as resp:
|
|
597
598
|
geo = json.loads(resp.read().decode("utf-8"))
|
|
598
599
|
locations = geo.get("location") or []
|
|
@@ -604,7 +605,7 @@ def _build_qweather_engine(spec: dict[str, Any]) -> Any:
|
|
|
604
605
|
|
|
605
606
|
# 2) 实时天气
|
|
606
607
|
now_url = f"https://devapi.qweather.com/v7/weather/now?location={loc_id}&key={key}"
|
|
607
|
-
req2 = urllib.request.Request(now_url, headers={"User-Agent":
|
|
608
|
+
req2 = urllib.request.Request(now_url, headers={"User-Agent": UA})
|
|
608
609
|
with http_open(req2, timeout=to, engine=spec.get("_name", "")) as resp:
|
|
609
610
|
data = json.loads(resp.read().decode("utf-8"))
|
|
610
611
|
now = data.get("now") or {}
|
|
@@ -731,7 +732,7 @@ def _build_rfc_editor_engine(spec: dict[str, Any]) -> Any:
|
|
|
731
732
|
「RFC 9000」直接定位单篇;「QUIC RFC」按标题搜索 RFC 类型文档。
|
|
732
733
|
"""
|
|
733
734
|
timeout = spec.get("timeout", 15)
|
|
734
|
-
_HEADERS = {"User-Agent":
|
|
735
|
+
_HEADERS = {"User-Agent": UA, "Accept": "application/json"}
|
|
735
736
|
|
|
736
737
|
def _jget(url: str, to: float) -> dict:
|
|
737
738
|
req = urllib.request.Request(url, headers=_HEADERS)
|
|
@@ -813,7 +814,7 @@ def _build_marginalia_engine(spec: dict[str, Any]) -> Any:
|
|
|
813
814
|
url = f"{base}/search?query={up.quote(query)}"
|
|
814
815
|
try:
|
|
815
816
|
with http_open(urllib.request.Request(
|
|
816
|
-
url, headers={"User-Agent":
|
|
817
|
+
url, headers={"User-Agent": UA}), timeout=to, engine=spec.get("_name", "")) as resp:
|
|
817
818
|
page = resp.read().decode("utf-8", "replace")
|
|
818
819
|
except Exception as e:
|
|
819
820
|
logger.warning(f"Marginalia 失败: {e}")
|
|
@@ -824,7 +825,7 @@ def _build_marginalia_engine(spec: dict[str, Any]) -> Any:
|
|
|
824
825
|
try:
|
|
825
826
|
with http_open(urllib.request.Request(
|
|
826
827
|
base + gate.group(1).replace("&", "&"),
|
|
827
|
-
headers={"User-Agent":
|
|
828
|
+
headers={"User-Agent": UA}), timeout=to, engine=spec.get("_name", "")) as resp:
|
|
828
829
|
page = resp.read().decode("utf-8", "replace")
|
|
829
830
|
except Exception as e:
|
|
830
831
|
logger.warning(f"Marginalia sst 复访失败: {e}")
|
|
@@ -885,7 +886,7 @@ def _build_wiby_engine(spec: dict[str, Any]) -> Any:
|
|
|
885
886
|
url = f"https://wiby.me/json/?q={up.quote(query)}"
|
|
886
887
|
try:
|
|
887
888
|
with http_open(urllib.request.Request(
|
|
888
|
-
url, headers={"User-Agent":
|
|
889
|
+
url, headers={"User-Agent": UA}), timeout=to, engine=spec.get("_name", "")) as resp:
|
|
889
890
|
data = json.loads(resp.read().decode("utf-8", "replace"))
|
|
890
891
|
except Exception as e:
|
|
891
892
|
logger.warning(f"Wiby 失败: {e}")
|
|
@@ -16,6 +16,7 @@ import urllib.parse
|
|
|
16
16
|
import urllib.request
|
|
17
17
|
from typing import Any
|
|
18
18
|
|
|
19
|
+
from engines_http import UA
|
|
19
20
|
from engines_base import (
|
|
20
21
|
safe_search, _run, _resolve, _get_path, _coerce_field, _detect_anti_bot,
|
|
21
22
|
http_open, rank_score,
|
|
@@ -94,7 +95,7 @@ def _build_fred_engine(spec: dict[str, Any]) -> Any:
|
|
|
94
95
|
return []
|
|
95
96
|
url = f"https://fred.stlouisfed.org/graph/fredgraph.csv?id={series_id}"
|
|
96
97
|
try:
|
|
97
|
-
req = urllib.request.Request(url, headers={"User-Agent":
|
|
98
|
+
req = urllib.request.Request(url, headers={"User-Agent": UA})
|
|
98
99
|
with http_open(req, timeout=to, engine=spec.get("_name", "")) as resp:
|
|
99
100
|
text = resp.read().decode("utf-8", "replace")
|
|
100
101
|
except Exception as e:
|
|
@@ -258,7 +259,7 @@ def _build_fx_rate_engine(spec: dict[str, Any]) -> Any:
|
|
|
258
259
|
if not base or not target:
|
|
259
260
|
return []
|
|
260
261
|
try:
|
|
261
|
-
req = urllib.request.Request(api_url + base, headers={"User-Agent":
|
|
262
|
+
req = urllib.request.Request(api_url + base, headers={"User-Agent": UA})
|
|
262
263
|
with http_open(req, timeout=to, engine=spec.get("_name", "")) as resp:
|
|
263
264
|
data = json.loads(resp.read().decode("utf-8", "replace"))
|
|
264
265
|
except Exception as e:
|
|
@@ -331,7 +332,7 @@ def _build_worldbank_engine(spec: dict[str, Any]) -> Any:
|
|
|
331
332
|
def _engine(query: str, n: int = 5, _timeout: float | None = None, **kwargs) -> list[dict[str, Any]]:
|
|
332
333
|
import urllib.parse as up
|
|
333
334
|
to = _timeout or timeout
|
|
334
|
-
headers = {"User-Agent":
|
|
335
|
+
headers = {"User-Agent": UA}
|
|
335
336
|
cc, ind, ind_label = _parse(query)
|
|
336
337
|
if not cc or not ind:
|
|
337
338
|
return []
|
|
@@ -693,7 +694,7 @@ def _build_eurostat_engine(spec: dict[str, Any]) -> Any:
|
|
|
693
694
|
支持 EU 国家/欧盟/欧元区的 GDP、人均GDP、失业率、人口年度查询。
|
|
694
695
|
"""
|
|
695
696
|
timeout = spec.get("timeout", 15)
|
|
696
|
-
_HEADERS = {"User-Agent":
|
|
697
|
+
_HEADERS = {"User-Agent": UA, "Accept": "application/json"}
|
|
697
698
|
_BASE = "https://ec.europa.eu/eurostat/api/dissemination/statistics/1.0/data"
|
|
698
699
|
|
|
699
700
|
def _jget(url: str, to: float) -> dict:
|
|
@@ -31,6 +31,7 @@ import urllib.request
|
|
|
31
31
|
from pathlib import Path
|
|
32
32
|
from typing import Any
|
|
33
33
|
|
|
34
|
+
from engines_http import UA
|
|
34
35
|
from engines_base import safe_search, http_open, rank_score
|
|
35
36
|
|
|
36
37
|
# 上游:静态全量目录。Cloudflare 前置,支持 ETag(本 builder 刻意不用,见文件头)。
|
|
@@ -116,7 +117,7 @@ def _load_plugins(timeout: float) -> list[dict[str, Any]]:
|
|
|
116
117
|
try:
|
|
117
118
|
req = urllib.request.Request(
|
|
118
119
|
_DSHOPEN_INDEX_URL,
|
|
119
|
-
headers={"User-Agent":
|
|
120
|
+
headers={"User-Agent": UA, "Accept": "application/json"},
|
|
120
121
|
)
|
|
121
122
|
with http_open(req, timeout=timeout, engine="dshopen") as resp:
|
|
122
123
|
payload = json.loads(resp.read())
|
|
@@ -85,25 +85,26 @@ def _read_disk_feed(url: str) -> list[dict[str, Any]] | None:
|
|
|
85
85
|
|
|
86
86
|
|
|
87
87
|
def _write_disk_feed(url: str, items: list[dict[str, Any]]) -> None:
|
|
88
|
-
"""
|
|
88
|
+
"""原子更新跨进程轻量磁盘缓存(读改写全程持锁,防并发互覆盖)。"""
|
|
89
89
|
if not items or "example.test" in url:
|
|
90
90
|
return
|
|
91
91
|
try:
|
|
92
92
|
import argo_paths
|
|
93
93
|
import json
|
|
94
94
|
p = argo_paths.state_path("feed_cache.json")
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
95
|
+
with argo_paths.file_lock(p):
|
|
96
|
+
data: dict[str, Any] = {}
|
|
97
|
+
if p.is_file():
|
|
98
|
+
try:
|
|
99
|
+
with open(p, "r", encoding="utf-8") as f:
|
|
100
|
+
data = json.load(f)
|
|
101
|
+
except Exception:
|
|
102
|
+
data = {}
|
|
103
|
+
data[url] = {"ts": time.time(), "items": items}
|
|
104
|
+
now = time.time()
|
|
105
|
+
# 清理 24h 前历史条目,防无界膨胀
|
|
106
|
+
data = {k: v for k, v in data.items() if isinstance(v, dict) and (now - float(v.get("ts", 0))) < 86400}
|
|
107
|
+
argo_paths.atomic_write_json(p, data)
|
|
107
108
|
except Exception:
|
|
108
109
|
pass
|
|
109
110
|
|
|
@@ -301,6 +302,10 @@ def _build_rss_feed_engine(spec: dict[str, Any]) -> Any:
|
|
|
301
302
|
min_ratio = float(spec.get("match_min_ratio", 0.34))
|
|
302
303
|
snippet_max = int(spec.get("snippet_max", 300))
|
|
303
304
|
hot_base = float(spec.get("hot_base_score", 0.55))
|
|
305
|
+
# 部分站点(如 linux.do)的 Cloudflare 按 TLS 指纹拦 Python 客户端:
|
|
306
|
+
# urllib 403、curl/curl_cffi 200。声明 tls_impersonate: true 的源走
|
|
307
|
+
# curl_cffi 指纹伪造;其余源保持 urllib 路径,行为不变。
|
|
308
|
+
tls_impersonate = bool(spec.get("tls_impersonate"))
|
|
304
309
|
|
|
305
310
|
def _row(it: dict[str, Any], rank: int, score: float,
|
|
306
311
|
label: str = "") -> dict[str, Any]:
|
|
@@ -330,12 +335,22 @@ def _build_rss_feed_engine(spec: dict[str, Any]) -> Any:
|
|
|
330
335
|
last_exc: Exception | None = None
|
|
331
336
|
for attempt in (1, 2):
|
|
332
337
|
try:
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
338
|
+
if tls_impersonate:
|
|
339
|
+
from http_client import HttpClient
|
|
340
|
+
client = HttpClient(timeout=one_timeout, max_retries=0)
|
|
341
|
+
resp = client.get_impersonated(
|
|
342
|
+
url, extra_headers={"User-Agent": _UA,
|
|
343
|
+
"Accept": "*/*"})
|
|
344
|
+
if resp.get("status") != 200:
|
|
345
|
+
raise IOError(f"HTTP {resp.get('status')}")
|
|
346
|
+
raw = resp.get("text") or ""
|
|
347
|
+
else:
|
|
348
|
+
req = urllib.request.Request(
|
|
349
|
+
url, headers={"User-Agent": _UA, "Accept": "*/*"})
|
|
350
|
+
with http_open(req, timeout=one_timeout, engine=name) as resp:
|
|
351
|
+
# utf-8-sig 去掉美联储 press_all.xml 开头的 BOM。
|
|
352
|
+
# ElementTree 见到 U+FEFF 会整份解析失败。
|
|
353
|
+
raw = resp.read().decode("utf-8-sig", "replace")
|
|
339
354
|
items = _parse_feed(raw)
|
|
340
355
|
_feed_cache[url] = (time.monotonic(), items)
|
|
341
356
|
_write_disk_feed(url, items)
|
|
@@ -16,6 +16,7 @@ import urllib.request
|
|
|
16
16
|
from typing import Any
|
|
17
17
|
|
|
18
18
|
from engine_env import get_env
|
|
19
|
+
from engines_http import UA
|
|
19
20
|
from engines_base import (
|
|
20
21
|
rank_score,
|
|
21
22
|
safe_search, _detect_anti_bot,
|
|
@@ -220,7 +221,7 @@ def _build_opencorporates_engine(spec: dict[str, Any]) -> Any:
|
|
|
220
221
|
f"?q={urllib.parse.quote(q2)}&per_page={min(n, 10)}"
|
|
221
222
|
+ (f"&api_token={urllib.parse.quote(_token)}" if _token else "")
|
|
222
223
|
)
|
|
223
|
-
headers = {"User-Agent":
|
|
224
|
+
headers = {"User-Agent": UA, "Accept": "application/json"}
|
|
224
225
|
try:
|
|
225
226
|
with http_open(urllib.request.Request(url, headers=headers), timeout=to, engine=spec.get("_name", "")) as resp:
|
|
226
227
|
data = json.loads(resp.read().decode("utf-8", "replace"))
|
|
@@ -24,6 +24,7 @@ import urllib.request
|
|
|
24
24
|
import xml.etree.ElementTree as ET
|
|
25
25
|
from typing import Any
|
|
26
26
|
|
|
27
|
+
from engines_http import UA
|
|
27
28
|
from engines_base import safe_search, _http_get_raw, http_open, rank_score
|
|
28
29
|
from bounded_run import run_bounded
|
|
29
30
|
from engines_http import (
|
|
@@ -710,7 +711,7 @@ def _build_google_news_engine(spec: dict[str, Any]) -> Any:
|
|
|
710
711
|
hl, gl, ceid = _news_locale(q)
|
|
711
712
|
url = (f"https://news.google.com/rss/search?q={urllib.parse.quote(q)}"
|
|
712
713
|
f"&hl={hl}&gl={gl}&ceid={ceid}")
|
|
713
|
-
raw = _http_get_raw(url, {"User-Agent":
|
|
714
|
+
raw = _http_get_raw(url, {"User-Agent": UA, "Accept": "application/rss+xml"},
|
|
714
715
|
to, engine=spec.get("_name", "google_news"))
|
|
715
716
|
if raw is None:
|
|
716
717
|
return []
|
|
@@ -763,7 +764,7 @@ def _build_met_museum_engine(spec: dict[str, Any]) -> Any:
|
|
|
763
764
|
return []
|
|
764
765
|
to = _timeout or timeout
|
|
765
766
|
engine_name = spec.get("_name", "met_museum")
|
|
766
|
-
headers = {"User-Agent":
|
|
767
|
+
headers = {"User-Agent": UA, "Accept": "application/json"}
|
|
767
768
|
search_url = f"{_SEARCH_BASE}/search?q={urllib.parse.quote(q)}&hasImages=true"
|
|
768
769
|
raw = _http_get_raw(search_url, headers, to, engine=engine_name)
|
|
769
770
|
if raw is None:
|
|
@@ -15,10 +15,15 @@ import urllib.request
|
|
|
15
15
|
from html import unescape as _unescape
|
|
16
16
|
from typing import Any
|
|
17
17
|
|
|
18
|
+
from engines_http import UA
|
|
18
19
|
from engines_base import (
|
|
19
20
|
rank_score,
|
|
20
21
|
safe_search, http_open,
|
|
21
22
|
)
|
|
23
|
+
from retry_policy import (
|
|
24
|
+
NON_RETRYABLE_STATUS as _NON_RETRYABLE_STATUS,
|
|
25
|
+
classify_error_status,
|
|
26
|
+
)
|
|
22
27
|
|
|
23
28
|
logger = logging.getLogger("unified_search.engines")
|
|
24
29
|
|
|
@@ -213,7 +218,7 @@ def _build_itunes_engine(spec: dict[str, Any]) -> Any:
|
|
|
213
218
|
base = spec.get("url") or "https://itunes.apple.com/search"
|
|
214
219
|
lookup_base = (base.replace("/search", "/lookup") if "/search" in base
|
|
215
220
|
else "https://itunes.apple.com/lookup")
|
|
216
|
-
ua_headers = {"User-Agent":
|
|
221
|
+
ua_headers = {"User-Agent": UA, "Accept": "application/json"}
|
|
217
222
|
|
|
218
223
|
def _get_json(url: str, to: float) -> dict[str, Any]:
|
|
219
224
|
req = urllib.request.Request(url, headers=ua_headers)
|
|
@@ -464,10 +469,18 @@ def _build_itunes_engine(spec: dict[str, Any]) -> Any:
|
|
|
464
469
|
return _engine
|
|
465
470
|
|
|
466
471
|
|
|
467
|
-
# ── TheSportsDB 体育(免认证 test key=
|
|
472
|
+
# ── TheSportsDB 体育(免认证 test key=123) ──────────────────────────────────
|
|
473
|
+
# 旧免费 key=3 已被厂方永久停用(403 正文:"The old '3' Free Sports API key is
|
|
474
|
+
# permanently disabled, Please use the new test key \"123\"")。2026-11-17 实测
|
|
475
|
+
# key=123 对 searchplayers/searchteams 返回 200,key=3 恒 403、key=1 报
|
|
476
|
+
# "Invalid Premium API key"。换 key 前该源对任何查询都是确定性 403。
|
|
468
477
|
|
|
469
|
-
_SPORTSDB_BASE = "https://www.thesportsdb.com/api/v1/json/
|
|
470
|
-
_SPORTSDB_UA =
|
|
478
|
+
_SPORTSDB_BASE = "https://www.thesportsdb.com/api/v1/json/123"
|
|
479
|
+
_SPORTSDB_UA = UA
|
|
480
|
+
# 实体问早停线:player/team 单条 rel 到这条线就说明主实体已到手,继续扇出
|
|
481
|
+
# 只是同一答案的重复请求(旧实现最多 15 次串行请求,实测 34s 直接吃掉引擎
|
|
482
|
+
# 超时)。赛事问不套这条线——「World Cup 2022」要的是多实体多样性。
|
|
483
|
+
_ENTITY_HIT_FLOOR = 0.9
|
|
471
484
|
|
|
472
485
|
# 高频中文球员/球队 → TheSportsDB 英文检索名(公开 API 基本只认拉丁文)
|
|
473
486
|
_SPORTS_ZH_ALIASES: dict[str, str] = {
|
|
@@ -511,7 +524,7 @@ def _sports_expand_aliases(query: str) -> list[str]:
|
|
|
511
524
|
|
|
512
525
|
|
|
513
526
|
def _build_thesportsdb_engine(spec: dict[str, Any]) -> Any:
|
|
514
|
-
"""TheSportsDB 球员/球队/赛事搜索(api key=
|
|
527
|
+
"""TheSportsDB 球员/球队/赛事搜索(api key=123 公开测试钥,免认证)。
|
|
515
528
|
|
|
516
529
|
并行查 searchplayers / searchteams / searchevents,合并去重。
|
|
517
530
|
"""
|
|
@@ -520,11 +533,21 @@ def _build_thesportsdb_engine(spec: dict[str, Any]) -> Any:
|
|
|
520
533
|
|
|
521
534
|
def _fetch(path: str, params: dict[str, str], to: float) -> Any:
|
|
522
535
|
url = f"{_SPORTSDB_BASE}/{path}?" + urllib.parse.urlencode(params)
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
536
|
+
# 瞬时错误(SSL EOF、握手超时、5xx)重试一次:实体问早停后整台引擎只剩
|
|
537
|
+
# 一次请求,一次网络抖动就是全盘 0 结果,而 403/配额这类确定性失败不重试。
|
|
538
|
+
last: Exception | None = None
|
|
539
|
+
for _attempt in range(2):
|
|
540
|
+
req = urllib.request.Request(
|
|
541
|
+
url, headers={"User-Agent": _SPORTSDB_UA, "Accept": "application/json"},
|
|
542
|
+
)
|
|
543
|
+
try:
|
|
544
|
+
with http_open(req, timeout=to, engine=spec.get("_name", "")) as resp:
|
|
545
|
+
return json.loads(resp.read().decode("utf-8", "replace"))
|
|
546
|
+
except Exception as e:
|
|
547
|
+
last = e
|
|
548
|
+
if classify_error_status(str(e)) in _NON_RETRYABLE_STATUS:
|
|
549
|
+
raise
|
|
550
|
+
raise last # type: ignore[misc]
|
|
528
551
|
|
|
529
552
|
@safe_search
|
|
530
553
|
def _engine(query: str, n: int = 5, _timeout: float | None = None, **kwargs) -> list[dict[str, Any]]:
|
|
@@ -623,12 +646,22 @@ def _build_thesportsdb_engine(spec: dict[str, Any]) -> Any:
|
|
|
623
646
|
|
|
624
647
|
q_token_set = {t.lower() for t in meaningful}
|
|
625
648
|
|
|
649
|
+
# 确定性失败(配额/鉴权/封锁)不重试:变体与端点只是同一堵墙的不同叫法。
|
|
650
|
+
fatal = False
|
|
651
|
+
strong_hit = False
|
|
626
652
|
for v in variants:
|
|
653
|
+
if fatal or strong_hit:
|
|
654
|
+
break
|
|
627
655
|
for path, param_k, kind, title_k, id_k, snip_fn in endpoints:
|
|
656
|
+
if strong_hit:
|
|
657
|
+
break
|
|
628
658
|
try:
|
|
629
659
|
data = _fetch(path, {param_k: v}, to)
|
|
630
660
|
except Exception as e:
|
|
631
661
|
logger.warning(f"TheSportsDB {path} 失败: {e}")
|
|
662
|
+
if classify_error_status(str(e)) in _NON_RETRYABLE_STATUS:
|
|
663
|
+
fatal = True
|
|
664
|
+
break
|
|
632
665
|
continue
|
|
633
666
|
items = data.get(list_keys[path]) if isinstance(data, dict) else None
|
|
634
667
|
if not items:
|
|
@@ -685,8 +718,13 @@ def _build_thesportsdb_engine(spec: dict[str, Any]) -> Any:
|
|
|
685
718
|
rel = 0.35 + 0.25 * overlap
|
|
686
719
|
if v.lower() in title.lower():
|
|
687
720
|
rel += 0.25
|
|
688
|
-
# 全名变体(Stephen Curry
|
|
689
|
-
|
|
721
|
+
# 全名变体(Stephen Curry)精确命中加权。整句变体带停用词
|
|
722
|
+
# (club/球队)时与 title 不等,但剥掉停用词后全等,同样算
|
|
723
|
+
# 精确命中——否则首个变体永远吃不到这条加权。
|
|
724
|
+
v_norm = " ".join(meaningful).lower()
|
|
725
|
+
if (" " in v and v.lower() == title.lower()) or (
|
|
726
|
+
v_norm and v_norm == title.lower()
|
|
727
|
+
):
|
|
690
728
|
rel += 0.3
|
|
691
729
|
seen.add(key)
|
|
692
730
|
href = url_tpl[kind].format(id=iid) if iid else ""
|
|
@@ -700,6 +738,15 @@ def _build_thesportsdb_engine(spec: dict[str, Any]) -> Any:
|
|
|
700
738
|
"_kind": kind,
|
|
701
739
|
"_rel": rel,
|
|
702
740
|
})
|
|
741
|
+
# 实体问早停:球员/球队强命中即收工。判据不能只看 prefer_entity——
|
|
742
|
+
# 调度层 _entity_core_query 会剥掉 club/球队 等属性词,「Cristiano
|
|
743
|
+
# Ronaldo」这类裸实体名到引擎时已无属性词,仍必须早停,否则扇出
|
|
744
|
+
# 十几次请求(实测 8s,管道 6s 预算下直接 0 结果)。赛事问
|
|
745
|
+
# (prefer_event)不套这条线,保持多实体多样性。
|
|
746
|
+
if (kind in ("player", "team") and not prefer_event
|
|
747
|
+
and rel >= _ENTITY_HIT_FLOOR):
|
|
748
|
+
strong_hit = True
|
|
749
|
+
break
|
|
703
750
|
# 已有高相关实体则早停
|
|
704
751
|
if sum(1 for r in bucket if r.get("_rel", 0) >= 0.5) >= n:
|
|
705
752
|
break
|
|
@@ -16,6 +16,7 @@ import urllib.request
|
|
|
16
16
|
from typing import Any
|
|
17
17
|
|
|
18
18
|
from cjk_tokens import cjk_term_grams
|
|
19
|
+
from engines_http import UA
|
|
19
20
|
from engines_base import (
|
|
20
21
|
rank_score,
|
|
21
22
|
safe_search, http_open,
|
|
@@ -44,7 +45,7 @@ def _build_openfda_engine(spec: dict[str, Any]) -> Any:
|
|
|
44
45
|
"search": search, "limit": min(n, 20)})
|
|
45
46
|
try:
|
|
46
47
|
with http_open(urllib.request.Request(
|
|
47
|
-
url, headers={"User-Agent":
|
|
48
|
+
url, headers={"User-Agent": UA, "Accept": "application/json"}), timeout=to, engine=spec.get("_name", "")) as resp:
|
|
48
49
|
data = json.loads(resp.read().decode("utf-8", "replace"))
|
|
49
50
|
except Exception as e:
|
|
50
51
|
# 回退:全文检索
|
|
@@ -53,7 +54,7 @@ def _build_openfda_engine(spec: dict[str, Any]) -> Any:
|
|
|
53
54
|
"search": q, "limit": min(n, 20),
|
|
54
55
|
})
|
|
55
56
|
with http_open(urllib.request.Request(
|
|
56
|
-
url2, headers={"User-Agent":
|
|
57
|
+
url2, headers={"User-Agent": UA}), timeout=to, engine=spec.get("_name", "")) as resp:
|
|
57
58
|
data = json.loads(resp.read().decode("utf-8", "replace"))
|
|
58
59
|
except Exception as e2:
|
|
59
60
|
logger.warning(f"openfda 失败: {e2}")
|
|
@@ -199,7 +200,7 @@ def _build_pubchem_engine(spec: dict[str, Any]) -> Any:
|
|
|
199
200
|
质量闸门:ChEMBL 结果须与查询 token 重叠,否则丢弃当 no-results(宁空勿假)。
|
|
200
201
|
"""
|
|
201
202
|
timeout = spec.get("timeout", 10)
|
|
202
|
-
_HEADERS = {"User-Agent":
|
|
203
|
+
_HEADERS = {"User-Agent": UA, "Accept": "application/json"}
|
|
203
204
|
|
|
204
205
|
def _jget(url: str, to: float) -> dict:
|
|
205
206
|
req = urllib.request.Request(url, headers=_HEADERS)
|
|
@@ -329,7 +330,7 @@ def _build_gbif_engine(spec: dict[str, Any]) -> Any:
|
|
|
329
330
|
学名/俗名搜索,优先学名包含查询词的 ACCEPTED 物种条目。
|
|
330
331
|
"""
|
|
331
332
|
timeout = spec.get("timeout", 12)
|
|
332
|
-
_HEADERS = {"User-Agent":
|
|
333
|
+
_HEADERS = {"User-Agent": UA}
|
|
333
334
|
|
|
334
335
|
def _jget(url: str, to: float) -> dict:
|
|
335
336
|
req = urllib.request.Request(url, headers=_HEADERS)
|
|
@@ -426,7 +427,7 @@ def _build_uniprot_engine(spec: dict[str, Any]) -> Any:
|
|
|
426
427
|
中英混合查询只取 ASCII token(UniProt 不索引中文),纯中文查高频蛋白名映射表。
|
|
427
428
|
"""
|
|
428
429
|
timeout = spec.get("timeout", 12)
|
|
429
|
-
_HEADERS = {"User-Agent":
|
|
430
|
+
_HEADERS = {"User-Agent": UA, "Accept": "application/json"}
|
|
430
431
|
|
|
431
432
|
@safe_search
|
|
432
433
|
def _engine(query: str, n: int = 5, _timeout: float | None = None, **kwargs) -> list[dict[str, Any]]:
|
|
@@ -482,7 +483,7 @@ def _build_rcsb_pdb_engine(spec: dict[str, Any]) -> Any:
|
|
|
482
483
|
全文搜索返回 PDB ID 列表,链接到 rcsb.org/structure/{id}。
|
|
483
484
|
"""
|
|
484
485
|
timeout = spec.get("timeout", 15)
|
|
485
|
-
_HEADERS = {"User-Agent":
|
|
486
|
+
_HEADERS = {"User-Agent": UA,
|
|
486
487
|
"Accept": "application/json", "Content-Type": "application/json"}
|
|
487
488
|
|
|
488
489
|
@safe_search
|
|
@@ -550,7 +551,7 @@ def _build_usgs_engine(spec: dict[str, Any]) -> Any:
|
|
|
550
551
|
按 place 字段过滤,命中地点相关地震。
|
|
551
552
|
"""
|
|
552
553
|
timeout = spec.get("timeout", 12)
|
|
553
|
-
_HEADERS = {"User-Agent":
|
|
554
|
+
_HEADERS = {"User-Agent": UA, "Accept": "application/json"}
|
|
554
555
|
|
|
555
556
|
@safe_search
|
|
556
557
|
def _engine(query: str, n: int = 5, _timeout: float | None = None, **kwargs) -> list[dict[str, Any]]:
|
|
@@ -21,6 +21,7 @@ import urllib.parse
|
|
|
21
21
|
import urllib.request
|
|
22
22
|
from typing import Any
|
|
23
23
|
|
|
24
|
+
from engines_http import UA
|
|
24
25
|
from engines_base import safe_search, http_open, rank_score
|
|
25
26
|
|
|
26
27
|
# ── 面向英文技能目录(explainx/skills.sh/skillsmp/clawhub)的轻量中英概念映射 ──
|
|
@@ -130,7 +131,7 @@ def _normalize_epoch(val: Any) -> str:
|
|
|
130
131
|
|
|
131
132
|
def _get_json(url: str, timeout: float, engine: str) -> Any:
|
|
132
133
|
req = urllib.request.Request(
|
|
133
|
-
url, headers={"User-Agent":
|
|
134
|
+
url, headers={"User-Agent": UA, "Accept": "application/json"}
|
|
134
135
|
)
|
|
135
136
|
with http_open(req, timeout=timeout, engine=engine) as resp:
|
|
136
137
|
return json.loads(resp.read())
|
|
@@ -16,7 +16,7 @@ from datetime import datetime
|
|
|
16
16
|
from email.utils import parsedate_to_datetime
|
|
17
17
|
from typing import Any
|
|
18
18
|
|
|
19
|
-
from engines_base import (safe_search, _run, _resolve, _get_path, _coerce_field, rank_score,
|
|
19
|
+
from engines_base import (safe_search, _run, _resolve, _get_path, _coerce_field, rank_score, UA,
|
|
20
20
|
_http_get_raw, mcp_error_of as _mcp_error_of, http_open, _note_http_failure)
|
|
21
21
|
from engine_env import get_env
|
|
22
22
|
|
|
@@ -533,7 +533,7 @@ def _build_stackoverflow_engine(spec: dict[str, Any]) -> Any:
|
|
|
533
533
|
if not q:
|
|
534
534
|
return []
|
|
535
535
|
url = f"https://api.stackexchange.com/2.3/search/advanced?order=desc&sort=relevance&q={up.quote(q)}&site={site}&pagesize={min(n, 10)}"
|
|
536
|
-
headers = {"User-Agent":
|
|
536
|
+
headers = {"User-Agent": UA, "Accept-Encoding": "gzip"}
|
|
537
537
|
req = urllib.request.Request(url, headers=headers)
|
|
538
538
|
try:
|
|
539
539
|
with http_open(req, timeout=to, engine=spec.get("_name", "")) as resp:
|
|
@@ -667,7 +667,7 @@ def _build_github_engine(spec: dict[str, Any]) -> Any:
|
|
|
667
667
|
endpoint = _github_endpoint(query, bool(token))
|
|
668
668
|
url = _github_url(endpoint, query, n)
|
|
669
669
|
headers = {
|
|
670
|
-
"User-Agent":
|
|
670
|
+
"User-Agent": UA,
|
|
671
671
|
"Accept": "application/vnd.github+json",
|
|
672
672
|
"X-GitHub-Api-Version": "2022-11-28",
|
|
673
673
|
}
|
|
@@ -130,9 +130,10 @@ def build_open_meteo_engine(spec: dict[str, Any]) -> Any:
|
|
|
130
130
|
# geocoding 只吃地名:完整天气问句(「今日北京天气」)先剥时间/疑问词,
|
|
131
131
|
# 否则上游 0 候选、引擎静默返回空
|
|
132
132
|
place_q = geo_core(query)
|
|
133
|
+
lang = "zh" if any("\u4e00" <= c <= "\u9fff" for c in place_q) else "en"
|
|
133
134
|
try:
|
|
134
135
|
geo = _http_json(
|
|
135
|
-
f"https://geocoding-api.open-meteo.com/v1/search?name={urllib.parse.quote(place_q)}&count=3&language=
|
|
136
|
+
f"https://geocoding-api.open-meteo.com/v1/search?name={urllib.parse.quote(place_q)}&count=3&language={lang}",
|
|
136
137
|
to, engine=spec.get("_name", ""))
|
|
137
138
|
except Exception as e:
|
|
138
139
|
logger.warning(f"Open-Meteo geocode 失败: {e}")
|
|
@@ -211,9 +212,13 @@ def build_open_meteo_engine(spec: dict[str, Any]) -> Any:
|
|
|
211
212
|
# = geocode + max(forecast)(实测 3.9-5.1s)。总上限 to+2s ≤ 串行
|
|
212
213
|
# 最坏 n×to;daemon 线程 + 轮询,卡住的 HTTP 读拖不垮止损
|
|
213
214
|
# (bounded_run 文档依据;与 wx.py:252「同坐标多端点并行」同哲学)。
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
215
|
+
if len(places) == 1:
|
|
216
|
+
one = _fetch_place((0, places[0]))
|
|
217
|
+
finished = [(0, one)] if one is not None else []
|
|
218
|
+
else:
|
|
219
|
+
finished, _unfinished = run_bounded(
|
|
220
|
+
list(enumerate(places)), _fetch_place,
|
|
221
|
+
wait_s=float(to) + 2.0, max_workers=3)
|
|
217
222
|
# 保序 + 打分:place 档位用 rank_score 的 rank(跨候选递减,与并行前
|
|
218
223
|
# 一致);组内逐日预报再用全局累积 rank 续排,保证整个结果序列严格
|
|
219
224
|
# 递减(同一 place 内 当前 > 第1天 > 第2天…,且下一个 place 的首条
|
package/scripts/engines_http.py
CHANGED
|
@@ -18,7 +18,56 @@ import urllib.parse
|
|
|
18
18
|
import urllib.request
|
|
19
19
|
from typing import Any, Callable
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
def _pkg_version() -> str:
|
|
22
|
+
"""版本单源:优先包内 __version__,兜底安装元数据。"""
|
|
23
|
+
try:
|
|
24
|
+
from argo_search import __version__ as _v
|
|
25
|
+
return _v
|
|
26
|
+
except Exception:
|
|
27
|
+
try:
|
|
28
|
+
from importlib.metadata import version as _meta_version
|
|
29
|
+
return _meta_version("argo-search")
|
|
30
|
+
except Exception:
|
|
31
|
+
return "unknown"
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
# 全仓唯一 User-Agent 真源(2026-11-18 收口):此前 55 处手抄字面量漂移出
|
|
35
|
+
# 7 个版本号(1.0~2.9,无一等于当前版),且多处带 RFC 6762 保留域假邮箱,
|
|
36
|
+
# 拿不到 Crossref/OpenAlex 礼貌池待遇、升版必漏改。新代码一律引用本常量,
|
|
37
|
+
# 版本字面量回潮由 tests/test_ua_single_source_gate.py 拦截。
|
|
38
|
+
UA = f"argo-search/{_pkg_version()} (+https://github.com/taxueseek/argo)"
|
|
39
|
+
|
|
40
|
+
# SEC EDGAR 强制 UA 带联系方式(官方政策:缺联系方式/假域会被 403),
|
|
41
|
+
# contact@example.com 是 SEC 官方文档认可的示例域。版本部分仍走 _pkg_version
|
|
42
|
+
# 单源;本常量只供 SEC 族 builder 引用,不进通用 UA 轮换。
|
|
43
|
+
UA_EDGAR = f"argo-search/{_pkg_version()} (contact@example.com)"
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def contact_email() -> str:
|
|
47
|
+
"""礼貌池联系方式(ARGO_CONTACT_EMAIL),未配置返回空串。
|
|
48
|
+
|
|
49
|
+
Crossref/OpenAlex 的 mailto 查询参数由此注入(engines_base 的
|
|
50
|
+
extra_params 循环);未配置时参数整体不发送——发保留域假邮箱会被官方
|
|
51
|
+
降权/封锁,不发只是降级为普通池,是诚实默认。
|
|
52
|
+
"""
|
|
53
|
+
from engine_env import get_env
|
|
54
|
+
return get_env("ARGO_CONTACT_EMAIL").strip()
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def normalize_ua_headers(headers: dict) -> dict:
|
|
58
|
+
"""把 spec 声明的历史手抄 UA 字面量统一指向单源。
|
|
59
|
+
|
|
60
|
+
spec/registry 里 `User-Agent: argo-search`(无版本号)是「用应用 UA」的
|
|
61
|
+
声明意图;历史 yaml 里的 argo-search/陈旧版本号 等字面量在构造期被归一
|
|
62
|
+
到本模块单源,避免每次升版手改几十份 yaml 与 builder。
|
|
63
|
+
"""
|
|
64
|
+
out: dict = {}
|
|
65
|
+
for k, v in headers.items():
|
|
66
|
+
if str(k).lower() == "user-agent" and str(v).strip().startswith("argo-search"):
|
|
67
|
+
out[k] = UA
|
|
68
|
+
else:
|
|
69
|
+
out[k] = v
|
|
70
|
+
return out
|
|
22
71
|
|
|
23
72
|
# 结构字符保留集:既有 %XX 编码、协议/路径/参数分隔符不重复转义
|
|
24
73
|
URL_SAFE = "/:?&=%,._~#+-"
|