1"""Send a lab message or answer a native request using the disposable operator."""23import json4import sys5from pathlib import Path67from rpc import Client, answer, public, tag8910def main(args):11 if not args or args[0] == "help":12 print("send TEXT | requests | answer EVENT_ID OPTION_ID | events | identity | export-key")13 return14 if args[0] == "export-key":15 print(json.loads(Path("/operator/owner.json").read_text())["secret"])16 return17 with Client() as client:18 if args[0] == "send":19 result = client.publish(9, " ".join(args[1:]), [["h", "lab"], ["p", public("agent")]])20 elif args[0] == "requests":21 result = client.browse("browseapprovals", {"state": "open"})22 elif args[0] == "answer":23 rows = client.query({"ids": [args[1]], "kinds": [9], "limit": 1})24 if not rows or tag(rows[0], "tinyagent") != "1":25 raise ValueError("The lab request was not found")26 result = answer(client, rows[0], " ".join(args[2:]))27 elif args[0] == "events":28 result = client.query({"kinds": [9, 1111, 40003], "#h": ["lab"], "limit": 30})29 elif args[0] == "identity":30 result = client.call("identity")31 else:32 raise ValueError("Unknown lab command; run help")33 print(json.dumps(result, indent=2))343536if __name__ == "__main__":37 main(sys.argv[1:])