Files
hermes-agent/tui_gateway/entry.py

39 lines
920 B
Python
Raw Normal View History

2026-04-02 19:06:42 -05:00
import json
2026-04-03 19:52:50 -05:00
import signal
2026-04-02 19:06:42 -05:00
import sys
2026-04-06 18:38:13 -05:00
from tui_gateway.server import handle_request, resolve_skin, write_json
2026-04-02 19:06:42 -05:00
2026-04-03 19:52:50 -05:00
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
2026-04-13 21:20:55 -05:00
signal.signal(signal.SIGINT, signal.SIG_IGN)
2026-04-03 19:52:50 -05:00
2026-04-02 19:06:42 -05:00
def main():
2026-04-06 18:38:13 -05:00
if not write_json({
2026-04-02 19:06:42 -05:00
"jsonrpc": "2.0",
"method": "event",
"params": {"type": "gateway.ready", "payload": {"skin": resolve_skin()}},
2026-04-06 18:38:13 -05:00
}):
sys.exit(0)
2026-04-02 19:06:42 -05:00
for raw in sys.stdin:
line = raw.strip()
if not line:
continue
try:
req = json.loads(line)
except json.JSONDecodeError:
2026-04-06 18:38:13 -05:00
if not write_json({"jsonrpc": "2.0", "error": {"code": -32700, "message": "parse error"}, "id": None}):
sys.exit(0)
2026-04-02 19:06:42 -05:00
continue
resp = handle_request(req)
if resp is not None:
2026-04-06 18:38:13 -05:00
if not write_json(resp):
sys.exit(0)
2026-04-02 19:06:42 -05:00
if __name__ == "__main__":
main()