← Back to Workflow
Internal

Verify Engine

Python script that verifies which AI engine (Claude or Gemini) is currently active in the Antigravity UI.

import urllib.request, json, asyncio, sys
import websockets

CDP_PORT = 9000

def get_chat_page():
    try:
        data = json.loads(urllib.request.urlopen(f'http://127.0.0.1:{CDP_PORT}/json/list', timeout=3).read())
    except Exception:
        print(f"FAILED: Cannot reach CDP on port {CDP_PORT}")
        sys.exit(1)
        
    candidates = []
    for t in data:
        if t.get('type') == 'page' and 'workbench.html' in t.get('url', ''):
            if 'jetski' not in t.get('url', ''):
                candidates.append(t)
                
    if candidates:
        return candidates[-1]
        
    print("FAILED: No active chat page found")
    sys.exit(1)

async def verify_model(target_model):
    page = get_chat_page()
    async with websockets.connect(page['webSocketDebuggerUrl']) as ws:
        msg_id = 1
        async def evaluate(js):
            nonlocal msg_id
            current_id = msg_id
            msg_id += 1
            await ws.send(json.dumps({
                'id': current_id, 'method': 'Runtime.evaluate',
                'params': {'expression': js, 'returnByValue': True}
            }))
            while True:
                resp = json.loads(await asyncio.wait_for(ws.recv(), timeout=2))
                if resp.get('id') == current_id:
                    return resp.get('result', {}).get('result', {}).get('value')
        
        current_text = await evaluate("""
            (function() {
                var btns = document.querySelectorAll('*[role="button"], button');
                for (var i = 0; i < btns.length; i++) {
                    var txt = (btns[i].textContent || "").trim();
                    var popup = btns[i].getAttribute('aria-haspopup');
                    if (popup && popup !== 'false') {
                        if (txt.includes('Gemini') || txt.includes('Claude') || txt.includes('GPT')) {
                            return txt;
                        }
                    }
                }
                return "Unknown Model";
            })()
        """)
        
        base_target = target_model.split(' ')[0].lower()
        if base_target in current_text.lower():
            print(f"SUCCESS: Engine physically verified. Currently running as {current_text}")
        else:
            print(f"FAILED: Expected {target_model}, but UI physically shows {current_text}.")
            sys.exit(1)

if __name__ == '__main__':
    if len(sys.argv) < 2:
        print("Usage: python verify_engine.py <TARGET_MODEL>")
        sys.exit(1)
    asyncio.run(verify_model(sys.argv[1]))

This is used in: