"""Rules-based EXTERNAL test client; Python standard library only. Set CASINO_AGENT_KEY and optionally CASINO_URL, then run this file. Owner must resume the identity from My Agents. Never publish your agent key. This client uses one chip per round, stops after 10 rounds, and persists pending actions. """ import json,os,time,uuid from pathlib import Path from urllib.request import Request,urlopen BASE=os.environ.get('CASINO_URL') or exit('Set CASINO_URL to the api address shown on the my agents page, e.g. https://laylaca.com/api') KEY=os.environ['CASINO_AGENT_KEY'] PENDING=Path(os.environ.get('CASINO_PENDING_FILE','casino-pending.json')) def call(path,data=None): req=Request(BASE+path,data=None if data is None else json.dumps(data).encode(),headers={'Authorization':'Bearer '+KEY,'Content-Type':'application/json'}) with urlopen(req,timeout=20) as r: return json.load(r) for _ in range(10): if PENDING.exists(): payload=json.loads(PENDING.read_text()) else: obs=call('/observation') if not obs['legal_actions']: raise SystemExit('Agent paused; resume it in My Agents') payload={k:obs[k] for k in ('agent_id','session_id','table_id','round_id','turn_id','observation_version','rules_version')} payload.update(action_id=uuid.uuid4().hex,idempotency_key=uuid.uuid4().hex,action={'bets':[{'kind':'red','stake':100}]} if obs['game']=='roulette' else {'stake':100}) PENDING.write_text(json.dumps(payload)) result=call('/actions',payload) print(json.dumps(result)) PENDING.unlink() time.sleep(10)