Download src/hai_relay/cli.py from smlflg/HAI-Relay: direct link, hf CLI and curl.
- Browser
- Download file 1.51 kB
-
https://huggingface.co/smlflg/HAI-Relay/resolve/main/src/hai_relay/cli.py
- Command line
-
hf download hf://smlflg/HAI-Relay/src/hai_relay/cli.py
-
curl -L -o cli.py https://huggingface.co/smlflg/HAI-Relay/resolve/main/src/hai_relay/cli.py
1.51 kB
| """HAI-Relay CLI entry point.""" | |
| from __future__ import annotations | |
| import argparse | |
| import asyncio | |
| import shlex | |
| from pathlib import Path | |
| from .authority import DenyAllAuthority, SubprocessAuthority | |
| from .custody import ensure_state_dir | |
| from .daemon import RelayDaemon | |
| from .dispatcher import AcpDispatchPort | |
| from .protocol import RelayProtocol | |
| from .registry import AgentRegistry | |
| from .service import RelayService | |
| from .store import RelayStore | |
| def main() -> None: | |
| parser = argparse.ArgumentParser(prog="hai-relay") | |
| sub = parser.add_subparsers(dest="command", required=True) | |
| serve = sub.add_parser("serve") | |
| serve.add_argument("--state-dir", type=Path, required=True) | |
| serve.add_argument("--socket", type=Path, required=True) | |
| serve.add_argument("--authority-command") | |
| args = parser.parse_args() | |
| if args.command == "serve": | |
| state_dir = ensure_state_dir(args.state_dir) | |
| authority = ( | |
| SubprocessAuthority(tuple(shlex.split(args.authority_command))) | |
| if args.authority_command | |
| else DenyAllAuthority() | |
| ) | |
| store = RelayStore(state_dir / "relay.sqlite3", state_dir=state_dir) | |
| service = RelayService(store, AgentRegistry(), authority, AcpDispatchPort()) | |
| protocol = RelayProtocol(service) | |
| try: | |
| asyncio.run(RelayDaemon(args.socket, protocol).serve()) | |
| except KeyboardInterrupt: | |
| pass | |
| finally: | |
| store.close() | |
| if __name__ == "__main__": | |
| main() | |