#!/usr/bin/env python3 """PolicyAdvisor example. Set these project names to match --project.""" import json import sys WORKSPACES = {"studio": "work", "notes": "personal"} def advise(context): session = context["session"] profile_id = WORKSPACES.get(session.get("project")) if profile_id is None: return None if context["event"] == "on_limit": return {"action": "wait"} if context["event"] != "launch" or session.get("profile_id"): return None # A mapped project uses the model tier the caller requested. tier = session.get("model_tier") provider = next((model["provider"] for model in context["models"] if model["tier"] == tier), None) profile = next( (candidate for candidate in context["profiles"] if candidate["provider"] == provider and candidate["id"] == profile_id), None, ) lane = "work_busy" if session.get("headless") else "personal_busy" now = context["request"]["now_secs"] if not profile or not profile["signed_in"] or profile[lane]: return {"action": "wait"} if (profile.get("held_until") or 0) > now: return {"action": "wait"} for key in ("window_5h", "window_7d"): window = profile.get(key) if window and window["used_percent"] >= 100: reset = window.get("reset_at") if reset is None or reset > now: return {"action": "wait"} return {"action": "proceed", "profile_id": profile_id} advice = advise(json.loads(sys.stdin.readline())) if advice is not None: print(json.dumps(advice))