"""From Settings > Environments with one paired isolated server, rename and open Voice.
Usage: setup-mobile.py SESSION [model-search]
The server must already have Canary 180M Flash installed and selected.
"""
import re,subprocess,sys
session=sys.argv[1]
def device(*args):
 r=subprocess.run(['agent-device',*args,'--session',session],capture_output=True,text=True)
 if r.returncode:raise RuntimeError(r.stdout+r.stderr)
 return r.stdout
def first(pattern):
 s=device('snapshot','-i');m=re.search(pattern,s)
 if not m:raise RuntimeError(s)
 return m[1]
def press(selector):device('press',selector,'--settle')
press(first(r'(@e\d+) \[button\] "Manage '))
press(first(r'(@e\d+) \[button\] "Expand details'))
device('fill',first(r'(@e\d+) \[text-field\]'),'Transcription demo','--settle')
device('back','--settle');press('label="Save"')
press('label="Navigate up"');press('label="Navigate up"');press('label="Voice"')
press('label="Transcription demo"');press('text="Use environment"')
press('label="Canary 180M Flash, Local model · 208 MB"')
if len(sys.argv)>2:
 device('fill','label="Search models or languages"',sys.argv[2],'--settle')
 device('back','--settle')
print(device('snapshot','-i'))
