From 6c0ffecb09d878bc5c98345bacd187e538c803a5 Mon Sep 17 00:00:00 2001 From: architect Date: Sun, 29 Nov 2026 22:23:50 +0300 Subject: [PATCH] [STAGE5] Migrate CamBot read tools --- docs/architecture/G5-MIGRATION.md | 2 ++ docs/architecture/REGISTRY/tool_gateway.yaml | 8 ++++++++ docs/architecture/STAGE-5.md | 2 +- ops/ai/tool_gateway_server.py | 8 ++++++++ ops/bots/hub/bots.py | 15 +++++++++++++++ 5 files changed, 34 insertions(+), 1 deletion(-) diff --git a/docs/architecture/G5-MIGRATION.md b/docs/architecture/G5-MIGRATION.md index 6809158..c947781 100644 --- a/docs/architecture/G5-MIGRATION.md +++ b/docs/architecture/G5-MIGRATION.md @@ -38,6 +38,8 @@ direct 127.0.0.1:9120 → blocked - feature flag `HUB_GATEWAY_SEARCH=1` включён; - `!reindex` в gateway-режиме отключён; - Jellyfin/Paperless 401 — отдельные auth-проблемы; +- `CamBot` мигрирован на gateway (`cam.scan`, `cam.status`), read-only; +- feature flag `HUB_GATEWAY_CAM=1` включён; камера не перенастраивалась; - hub-bots active, 9 ботов на связи. ## Порядок миграции diff --git a/docs/architecture/REGISTRY/tool_gateway.yaml b/docs/architecture/REGISTRY/tool_gateway.yaml index d51ffe2..3e6b17a 100644 --- a/docs/architecture/REGISTRY/tool_gateway.yaml +++ b/docs/architecture/REGISTRY/tool_gateway.yaml @@ -109,6 +109,14 @@ tools: mode: read local: paperless_search approval: false + - name: cam.scan + mode: read + local: cam_scan + approval: false + - name: cam.status + mode: read + local: cam_status + approval: false - name: audit.write gateway: http://127.0.0.1:9160/api/sprint/status mode: write diff --git a/docs/architecture/STAGE-5.md b/docs/architecture/STAGE-5.md index 2fb43c0..5ccb6bb 100644 --- a/docs/architecture/STAGE-5.md +++ b/docs/architecture/STAGE-5.md @@ -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+Search; MEDIA/INFRA/CAM/SECRETARY direct | +| S5-07 | Gate G5 | in_progress: Photo+Book+Home+Digest+Search+Cam; MEDIA/INFRA/SECRETARY direct | ## Tool Gateway runtime diff --git a/ops/ai/tool_gateway_server.py b/ops/ai/tool_gateway_server.py index f92e885..904196c 100644 --- a/ops/ai/tool_gateway_server.py +++ b/ops/ai/tool_gateway_server.py @@ -107,6 +107,14 @@ def local_call(handler, q=""): 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} + if handler == "cam_scan": + import subprocess + r = subprocess.run(["/usr/bin/python3", "/opt/hub-core/camera_discover.py"], + capture_output=True, text=True, timeout=120) + return {"ok": r.returncode == 0, "data": (r.stdout or "").strip(), "error": (r.stderr or "")[:200]} + if handler == "cam_status": + bot = _hub_module("bots").CamBot(None, None) + return {"ok": True, "data": bot._cam_status(), "error": None} raise ValueError("unknown local handler") diff --git a/ops/bots/hub/bots.py b/ops/bots/hub/bots.py index 9bef64b..b5605bc 100644 --- a/ops/bots/hub/bots.py +++ b/ops/bots/hub/bots.py @@ -1555,6 +1555,18 @@ class CamBot(Bot): def _cam_scan(self): """Найти камеры в сети (порт 554 и другие).""" + if os.environ.get("HUB_GATEWAY_CAM") == "1": + from .gateway import call + text = (call("cam.scan").get("data") or "").strip() + if not text: + return "Поиск ничего не вернул." + lines = text.splitlines() + head = [l for l in lines if l.startswith(("соседей", "похоже", "с открытыми"))] + found = [l for l in lines if l.startswith(" ") and "порты" in l] + res = ["**Поиск камер в сети**", ""] + head + if found: + res += [""] + found[:10] + return "\n".join(res) import subprocess try: out = subprocess.run(['/usr/bin/python3', '/opt/hub-core/camera_discover.py'], @@ -1574,6 +1586,9 @@ class CamBot(Bot): def _cam_status(self): """Что известно про камеры: Frigate и последний поиск.""" + if os.environ.get("HUB_GATEWAY_CAM") == "1": + from .gateway import call + return call("cam.status").get("data") or "Нет данных." lines = [] try: data, err = util.get('http://192.168.1.126:5000/api/stats')