Files
buryan-infra/ops/bots/hub/gateway.py
T
architect c7be3583e1
lint / hygiene (pull_request) Failing after 24s
standard / check (pull_request) Successful in 11s
lint / hygiene (push) Failing after 31s
standard / check (push) Successful in 11s
[STAGE5] Migrate BookBot to gateway local-tools
2026-11-29 22:07:37 +03:00

22 lines
575 B
Python

"""Tiny client for the Buryans Tool Gateway."""
import json
import urllib.parse
import urllib.request
BASE = "http://127.0.0.1:9137"
def call(tool, params=None):
url = BASE + "/v1/call?tool=" + urllib.parse.quote(tool)
if params:
url += "&" + urllib.parse.urlencode(params)
with urllib.request.urlopen(url, timeout=25) as r:
d = json.loads(r.read().decode())
body = d.get("body")
if isinstance(body, str):
try:
return json.loads(body)
except Exception:
return {"raw": body}
return body or {}