[STAGE5] Migrate SearchBot to gateway read tools
lint / hygiene (pull_request) Failing after 25s
standard / check (pull_request) Successful in 11s
lint / hygiene (push) Failing after 27s
standard / check (push) Successful in 10s

This commit is contained in:
architect committed 2026-11-29 22:19:44 +03:00
1 parent 235e7b829c
commit 97d037cb17
5 files changed
+119 -12

No files matched your search

+4
View File
@@ -34,6 +34,10 @@ direct 127.0.0.1:9120 → blocked
- `DigestBot` мигрирован на gateway (`catalog.content`, `digest.index`, `prometheus.*`, `seerr.counts`);
- feature flag `HUB_GATEWAY_DIGEST=1` включён;
- digest: индекс 93, targets 35, тревоги 2; Seerr 401 — отдельная auth-проблема;
- `SearchBot` мигрирован на gateway (`core.*`, `index.*`, `books.search`, `jellyfin.search`, `paperless.search`);
- feature flag `HUB_GATEWAY_SEARCH=1` включён;
- `!reindex` в gateway-режиме отключён;
- Jellyfin/Paperless 401 — отдельные auth-проблемы;
- hub-bots active, 9 ботов на связи.
## Порядок миграции
@@ -73,6 +73,42 @@ tools:
mode: read
local: seerr_counts
approval: false
- name: core.search
mode: read
local: core_search
approval: false
- name: core.card
mode: read
local: core_card
approval: false
- name: core.events
mode: read
local: core_events
approval: false
- name: index.search
mode: read
local: index_search
approval: false
- name: index.links
mode: read
local: index_links
approval: false
- name: index.stats
mode: read
local: index_stats
approval: false
- name: books.search
mode: read
local: books_search
approval: false
- name: jellyfin.search
mode: read
local: jellyfin_search
approval: false
- name: paperless.search
mode: read
local: paperless_search
approval: false
- name: audit.write
gateway: http://127.0.0.1:9160/api/sprint/status
mode: write
+1 -1
View File
@@ -27,7 +27,7 @@ GET /v1/models
| S5-04 | Memory | done: SQLite namespaced memory + TTL/search, tests 3/3 |
| S5-05 | Night Shift | done: timers 00:00/07:30, llm-night-start/stop |
| S5-06 | Tool Gateway / agent approvals | done: agent-gw enforced + approval queue; legacy migration = G5 |
| S5-07 | Gate G5 | in_progress: Photo+Book+Home+Digest migrated; остальные direct |
| S5-07 | Gate G5 | in_progress: Photo+Book+Home+Digest+Search; MEDIA/INFRA/CAM/SECRETARY direct |
## Tool Gateway runtime
+27
View File
@@ -80,6 +80,33 @@ def local_call(handler, q=""):
if handler == "prom_alerts":
data, err = _hub_module("sources").Prom().alerts()
return {"ok": not bool(err), "data": data, "error": err}
if handler == "core_search":
data, err = _hub_module("core_api").search(q)
return {"ok": not bool(err), "data": data, "error": err}
if handler == "core_card":
data, err = _hub_module("core_api").card(int(q))
return {"ok": not bool(err), "data": data, "error": err}
if handler == "core_events":
data, err = _hub_module("core_api").events()
return {"ok": not bool(err), "data": data, "error": err}
if handler == "index_search":
return {"ok": True, "data": _hub_module("index").search(q, 12), "error": None}
if handler == "index_links":
return {"ok": True, "data": _hub_module("index").links(q), "error": None}
if handler == "index_stats":
return {"ok": True, "data": _hub_module("index").stats(), "error": None}
if handler == "books_search":
data, err = _photo_local().Books().search(q, 5)
return {"ok": not bool(err), "data": data, "error": err}
if handler == "jellyfin_search":
data, err = _hub_module("sources").Jellyfin().search(q, 5)
return {"ok": not bool(err), "data": data, "error": err}
if handler == "paperless_search":
sources = _hub_module("sources")
data, err = sources.util.get(
f"{sources.CFG.paperless_url}/api/documents/?query={sources.util.quote(q)}&page_size=5",
{"Authorization": f"Token {sources.CFG.paperless_token}"}, ttl=60)
return {"ok": not bool(err), "data": data, "error": err}
raise ValueError("unknown local handler")
+51 -11
View File
@@ -1287,7 +1287,11 @@ class SearchBot(Bot):
def _card(self, eid):
if not eid.strip().isdigit():
return "Нужен номер карточки: `!card 74`. Найти номер — `!s <название>`."
data, err = core_api.card(int(eid))
if os.environ.get("HUB_GATEWAY_SEARCH") == "1":
from .gateway import call
data, err = call("core.card", {"q": eid}).get("data"), None
else:
data, err = core_api.card(int(eid))
if err:
return f"Ядро не ответило: {err}"
if not data:
@@ -1309,7 +1313,11 @@ class SearchBot(Bot):
return "\n".join(lines)
def _feed(self):
data, err = core_api.events()
if os.environ.get("HUB_GATEWAY_SEARCH") == "1":
from .gateway import call
data, err = call("core.events").get("data"), None
else:
data, err = core_api.events()
if err:
return f"Ядро не ответило: {err}"
items = (data or {}).get("items") or []
@@ -1331,7 +1339,11 @@ class SearchBot(Bot):
found = False
# сначала ядро — единый источник карточек
core, err = core_api.search(term)
if os.environ.get("HUB_GATEWAY_SEARCH") == "1":
from .gateway import call
core, err = call("core.search", {"q": term}).get("data"), None
else:
core, err = core_api.search(term)
if core and core.get("items"):
found = True
for r in core["items"][:12]:
@@ -1341,7 +1353,11 @@ class SearchBot(Bot):
return "\n".join(out)
# затем общий индекс — он знает про все сервисы
rows = index.search(term, 12)
if os.environ.get("HUB_GATEWAY_SEARCH") == "1":
from .gateway import call
rows = call("index.search", {"q": term}).get("data") or []
else:
rows = index.search(term, 12)
if rows:
found = True
for r in rows:
@@ -1349,23 +1365,37 @@ class SearchBot(Bot):
out.append(f"• [{r['kind']}] {r['title']}{sub}\n {r['url']}")
else:
# индекс пуст или не обновлён — спрашиваем живые сервисы
items, err = Jellyfin().search(term, 5)
if os.environ.get("HUB_GATEWAY_SEARCH") == "1":
from .gateway import call
items = call("jellyfin.search", {"q": term}).get("data") or []
err = None
else:
items, err = Jellyfin().search(term, 5)
if items:
found = True
out.append("**Медиа (вживую)**")
for it in items:
out.append(f"• {_fmt_item(it)}")
books, berr = local.Books().search(term, 5)
if os.environ.get("HUB_GATEWAY_SEARCH") == "1":
from .gateway import call
books = call("books.search", {"q": term}).get("data") or []
berr = None
else:
books, berr = local.Books().search(term, 5)
if books:
found = True
out.append("\n**Книги (вживую)**")
for r in books:
out.append(f"• {r['title']} — {r['author']}")
docs, _ = util.get(
f"{CFG.paperless_url}/api/documents/?query={util.quote(term)}&page_size=5",
{"Authorization": f"Token {CFG.paperless_token}"}, ttl=60)
if os.environ.get("HUB_GATEWAY_SEARCH") == "1":
from .gateway import call
docs = call("paperless.search", {"q": term}).get("data")
else:
docs, _ = util.get(
f"{CFG.paperless_url}/api/documents/?query={util.quote(term)}&page_size=5",
{"Authorization": f"Token {CFG.paperless_token}"}, ttl=60)
if docs and docs.get("results"):
found = True
out.append("\n**Документы**")
@@ -1377,7 +1407,11 @@ class SearchBot(Bot):
return "\n".join(out)
def _index(self):
s = index.stats()
if os.environ.get("HUB_GATEWAY_SEARCH") == "1":
from .gateway import call
s = call("index.stats").get("data") or {}
else:
s = index.stats()
lines = ["**Общий индекс**", "",
f"• Записей: {s['total']}",
f"• Обновлён: {s['built_at'] or 'ещё не строился'}"]
@@ -1390,6 +1424,8 @@ class SearchBot(Bot):
return "\n".join(lines)
def _reindex(self):
if os.environ.get("HUB_GATEWAY_SEARCH") == "1":
return "Reindex через gateway пока не включён; используйте прямой режим."
report = index.rebuild()
lines = ["**Индекс перестроен**", ""]
for name, r in report.items():
@@ -1402,7 +1438,11 @@ class SearchBot(Bot):
def _link(self, term):
if not term:
return "Что искать? `!link дюна`"
grouped = index.links(term)
if os.environ.get("HUB_GATEWAY_SEARCH") == "1":
from .gateway import call
grouped = call("index.links", {"q": term}).get("data") or {}
else:
grouped = index.links(term)
if not grouped:
return f"Связей по «{term}» не нашлось."
lines = [f"**Где встречается «{term}»**", ""]