#!/bin/bash
INST="friend-0f02c9c6"
# 创建 tunnel
TUN=$(curl -sS -X POST -H "Authorization: Bearer dev-admin-token" -H "Content-Type: application/json" \
  -d '{"instance_id":"'$INST'","ttl_seconds":600}' \
  "http://127.0.0.1:19088/api/v1/instances/$INST/tunnels")
TK=$(echo "$TUN" | python3 -c "import sys,json;u=json.load(sys.stdin).get('url','');import re;m=re.search(r'fctun_[a-f0-9]+',u);print(m.group(0) if m else '')")
echo "tunnel token: ${TK:0:20}..."
BASE="http://127.0.0.1:19088/panel/$INST"

echo "=== 渠道列表 ==="
curl -sS -m 10 -H "Cookie: friend_cluster_tunnel=$TK" "$BASE/api/llm/channels" | head -c 500
echo
echo "=== 路由列表 ==="
curl -sS -m 10 -H "Cookie: friend_cluster_tunnel=$TK" "$BASE/api/llm/routes" | python3 -c "
import sys,json
try:
    for r in json.load(sys.stdin):
        cands=r.get('candidates') or []
        print(r.get('purpose'), '->', [c.get('model_key') for c in cands])
except Exception as e: print('routes err:', e)
"
echo "=== LLM 健康 ==="
curl -sS -m 10 -H "Cookie: friend_cluster_tunnel=$TK" "$BASE/api/llm/health" | python3 -c "
import sys,json
try:
    d=json.load(sys.stdin)
    items = d if isinstance(d,list) else d.get('models') or []
    for m in items:
        st = m.get('model_state')
        if isinstance(st, dict): st = st.get('state')
        print(m.get('model_key'), '|', st)
except Exception as e: print('health err:', e)
"
