import urllib.request
import json
import ssl

def fetch_ls(port, csrf, method, args):
    url = f"http://127.0.0.1:{port}/exa.language_server_pb.LanguageServerService/{method}"
    hs = 'x-antigravity-csrf-token'
    req = urllib.request.Request(url, data=json.dumps(args).encode(), headers={
        'Content-Type': 'application/json',
        hs: csrf
    })
    try:
        with urllib.request.urlopen(req) as response:
            return json.loads(response.read().decode('utf-8'))
    except Exception as e:
        return f"Error: {e}"

p2 = 54285
c2 = "5e529def-51fe-4bde-9955-5eca7299bd89"

target = "370d1a09-1fa8-4aed-90d7-4024e36b3a2d"
args = {
    "cascadeId": target, 
    "verbosity": 1, 
    "workspaceUri": "file:///c:/Users/Variet-Worker/Desktop/gravity_control"
}

res = fetch_ls(p2, c2, "GetCascadeTrajectorySteps", args)
print(f"GetCascadeTrajectorySteps with workspaceUri = {str(res)[:200]}")
