#!/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
)

test_model() {
  local m="$1"
  local out t code body
  out=$(curl -s -o /tmp/r.json -w '%{http_code} %{time_total}' --max-time 60 -X POST \
    http://127.0.0.1:20128/v1/chat/completions \
    -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' \
    -d "{\"model\":\"$m\",\"messages\":[{\"role\":\"user\",\"content\":\"say hi in one word\"}],\"max_tokens\":8}" 2>/dev/null)
  code=${out%% *}
  t=${out##* }
  body=$(head -c 90 /tmp/r.json 2>/dev/null | tr -d '\n')
  printf '  %-46s %s  %6ss  %s\n' "$m" "$code" "$t" "$(echo "$body" | cut -c1-60)"
}

echo "===== ROUND 1 (cold) ====="
for m in claude-sonnet-4-5 code \
         gemini/gemini-3-flash-preview gemini/gemini-3.1-flash-lite-preview gemini/gemini-3.5-flash-lite \
         mimo-code \
         openrouter/nvidia/nemotron-3-ultra-550b-a55b:free openrouter/openrouter/free openrouter/typesafe/jev-1.13; do
  test_model "$m"
done

echo
echo "===== ROUND 2 (warm, same order) ====="
for m in gemini/gemini-3-flash-preview gemini/gemini-3.1-flash-lite-preview gemini/gemini-3.5-flash-lite mimo-code code; do
  test_model "$m"
done
