#!/usr/bin/env python3 """Deploy the Cyrus language brain API to Vercel (project cyrus-language-brain). One-off deploy script for the Sara v2 backend. Usage: python3 deploy_language_brain.py""" import json, subprocess, sys PKG = "/home/hatch/workspace/your_files/ideas/sara-v2-vercel" PROJECT = "cyrus-language-brain" FILES = [ ("api/index.py", "api/index.py"), ("requirements.txt", "requirements.txt"), ("vercel.json", "vercel.json"), ] ARG_LIMIT = 125000 def vercel_call(tool, args): payload = json.dumps(args, ensure_ascii=False) if len(payload.encode("utf-8")) > ARG_LIMIT: raise RuntimeError(f"payload too big for {tool}: {len(payload)} bytes") out = subprocess.run(["vercel", "call-tool", "--name", tool, "--arguments-json", payload], capture_output=True, text=True, timeout=300) d = json.loads(out.stdout) return json.loads(d["result"]["content"][0]["text"]) def main(): # 1. Disable SSO protection (on by default for new projects) try: r = vercel_call("update_project", { "idOrName": PROJECT, "requestBody": {"ssoProtection": None}, }) print("sso off:", json.dumps(r, ensure_ascii=False)[:200]) except Exception as e: print("sso off failed (continuing):", str(e)[:200]) # 2. Deploy files files = [] for src, dest in FILES: data = open(f"{PKG}/{src}", encoding="utf-8").read() files.append({"file": dest, "data": data, "encoding": "utf-8"}) args = {"requestBody": { "name": PROJECT, "files": files, "target": "production", "projectSettings": {"framework": None}, }} r = vercel_call("create_deployment", args) dep = r["result"]["deployment"] print(json.dumps({"project": PROJECT, "url": dep["url"], "state": dep["state"]}, ensure_ascii=False, indent=2)) if __name__ == "__main__": main()