#!/bin/bash
export LC_ALL=C
DB=/root/.9router/db/data.sqlite
KEY=$(python3 - "$DB" <<'PY'
import sqlite3,sys
c=sqlite3.connect(sys.argv[1])
cols=[r[1] for r in c.execute("pragma table_info(apiKeys)")]
print(c.execute("select * from apiKeys limit 1").fetchone()[cols.index('key')])
PY
)
echo "key length: ${#KEY}"

echo
echo "===== MODELS ====="
curl -s --max-time 10 -H "Authorization: Bearer $KEY" http://127.0.0.1:20128/v1/models \
  | python3 -c 'import sys,json;d=json.load(sys.stdin);print("\n".join("  "+m["id"] for m in d.get("data",[])))' 2>/dev/null

echo
echo "===== CALL mimo-code (short) ====="
curl -s -o /tmp/mimo_resp.json -w '  http=%{http_code} time=%{time_total}s\n' --max-time 90 \
  -X POST http://127.0.0.1:20128/v1/chat/completions \
  -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' \
  -d '{"model":"mimo-code","messages":[{"role":"user","content":"say hi"}],"max_tokens":8}' 2>/dev/null
head -c 400 /tmp/mimo_resp.json; echo

echo
echo "===== 9ROUTER LOG (last 30 lines) ====="
docker logs 9router --since 3m 2>&1 | tail -30
