#!/usr/bin/env python3
import subprocess, json
TK = open("/tmp/tk.txt").read().strip()
BASE = "http://127.0.0.1:19088/panel/friend-bb2f6f43"
H = ["-H", "Cookie: friend_cluster_tunnel=" + TK, "-H", "Content-Type: application/json"]
M_MISTRAL=3; M_NEMO=4; M_ORF=5
def cand(mid, mk):
    return {"target_type":"channel","channel_id":1,"channel_model_id":mid,"model_key":mk}
BRAIN=[cand(M_NEMO,"nvidia/nemotron-3-super-120b-a12b:free"), cand(M_ORF,"openrouter/free")]
MULTIMODAL=[cand(M_MISTRAL,"mistral-medium-latest"), cand(M_ORF,"openrouter/free")]
DEFAULT=[cand(M_MISTRAL,"mistral-medium-latest"), cand(M_NEMO,"nvidia/nemotron-3-super-120b-a12b:free"), cand(M_ORF,"openrouter/free")]
OTHER=["memory_narrative","memory_generator","memory_episode_extractor","memory_cognition_extractor","recall_memory_summary","auto_recall_query","auto_recall_refine","mind_weave_monitor","context_compression","importance_assessment","memory_cognition_dedup","memory_step_experience_extractor","memory_task_experience_summarizer","memory_operation_detail_learner","tool_param_validator","quick"]
routes={"brain_thinking":BRAIN,"tool_multimodal":MULTIMODAL,"default":DEFAULT}
for p in OTHER: routes[p]=BRAIN
ok=fail=0
for purpose,cands in routes.items():
    body=json.dumps({"use_streaming":False,"max_attempts":8,"total_budget_seconds":0,"all_cooling_policy":"fail_fast","enabled":True,"candidates":cands})
    r = subprocess.run(["curl","-sS","-m","15","-X","PUT"]+H+["-d",body,f"{BASE}/api/llm/routes/{purpose}"],capture_output=True,text=True)
    out=r.stdout.strip()
    if "\"error\"" in out or not out:
        fail+=1; print("FAIL",purpose,(out or r.stderr)[:150])
    else:
        ok+=1; print("OK",purpose)
print("done ok=%d fail=%d"%(ok,fail))
