|
15 | 15 | import pty |
16 | 16 | import select |
17 | 17 | import signal |
| 18 | +import shlex |
18 | 19 | import struct |
19 | 20 | import subprocess |
20 | 21 | import sys |
@@ -102,9 +103,31 @@ def emit_pi_event(group_id: str, payload: dict) -> None: |
102 | 103 | ) |
103 | 104 |
|
104 | 105 |
|
| 106 | +def build_publish_keypackage_cmd(): |
| 107 | + raw = os.environ.get("PI_RELAYS_JSON", "").strip() |
| 108 | + if not raw: |
| 109 | + return {"cmd": "publish_keypackage"} |
| 110 | + try: |
| 111 | + parsed = json.loads(raw) |
| 112 | + except Exception as err: |
| 113 | + log(f"invalid PI_RELAYS_JSON, ignoring: {err}") |
| 114 | + return {"cmd": "publish_keypackage"} |
| 115 | + if not isinstance(parsed, list): |
| 116 | + return {"cmd": "publish_keypackage"} |
| 117 | + relays = [str(item).strip() for item in parsed if str(item).strip()] |
| 118 | + if not relays: |
| 119 | + return {"cmd": "publish_keypackage"} |
| 120 | + return {"cmd": "publish_keypackage", "relays": relays} |
| 121 | + |
| 122 | + |
105 | 123 | def spawn_pi_rpc(label: str) -> subprocess.Popen[bytes]: |
106 | 124 | env = os.environ.copy() |
107 | | - cmd = ["pi", "--mode", "rpc", "--no-session", "--provider", "anthropic"] |
| 125 | + cmd = shlex.split( |
| 126 | + os.environ.get( |
| 127 | + "PI_CMD", |
| 128 | + "pi --mode rpc --no-session --provider anthropic", |
| 129 | + ) |
| 130 | + ) |
108 | 131 | model = os.environ.get("PI_MODEL") |
109 | 132 | if model: |
110 | 133 | cmd.extend(["--model", model]) |
@@ -981,8 +1004,7 @@ def main() -> None: |
981 | 1004 | if msg_type == "ready": |
982 | 1005 | my_pubkey = msg.get("pubkey") |
983 | 1006 | log(f"marmotd ready, pubkey={my_pubkey}") |
984 | | - send_to_marmotd({"cmd": "publish_keypackage"}) |
985 | | - continue |
| 1007 | + send_to_marmotd(build_publish_keypackage_cmd()) |
986 | 1008 |
|
987 | 1009 | if msg_type == "call_invite_received": |
988 | 1010 | call_id = str(msg.get("call_id", "")) |
|
0 commit comments