import os import sys import json import urllib.request import urllib.error # JULES_API_KEY should be passed as an environment variable or an argument API_KEY = os.environ.get("JULES_API_KEY") if not API_KEY and len(sys.argv) > 1: API_KEY = sys.argv[1] if not API_KEY: print("Error: JULES_API_KEY environment variable not set.") sys.exit(1) JULES_ENDPOINT = "https://jules.googleapis.com/v1alpha/sessions" SOURCE = "sources/github/mrhavens/intellecton" payload = { "prompt": "Test connection: Verify Jules API autonomous CI/CD link to the Intellecton Master Key.", "sourceContext": { "source": SOURCE, "githubRepoContext": { "startingBranch": "master" } }, "automationMode": "AUTO_CREATE_PR", "title": "Jules API Connection Test" } req = urllib.request.Request(JULES_ENDPOINT, method="POST") req.add_header("Content-Type", "application/json") req.add_header("x-goog-api-key", API_KEY) data = json.dumps(payload).encode("utf-8") print(f"Initiating autonomous Jules session on {SOURCE}...") try: with urllib.request.urlopen(req, data=data) as response: resp_data = response.read().decode("utf-8") session_info = json.loads(resp_data) print("Success! Jules Session Created:") print(json.dumps(session_info, indent=2)) print(f"\nSession ID: {session_info.get('id')}") print("You can now monitor this session via the API or wait for the PR.") except urllib.error.HTTPError as e: print(f"HTTP Error: {e.code} - {e.reason}") print(e.read().decode("utf-8")) except Exception as e: print(f"Error connecting to Jules API: {str(e)}")