#!/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 "=== LIVE call through 9router (same conditions as the real path) ==="
curl -s -o /tmp/r -w '  HTTP %{http_code}  %{time_total}s\n' --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":"mimo-code","messages":[{"role":"user","content":"hi"}],"max_tokens":8,"stream":true}' 2>/dev/null
head -c 300 /tmp/r; echo

echo
echo "=== 9router log for this call ==="
docker logs 9router --since 90s 2>&1 | grep -iE 'mimo|opencode|PROXY|ERROR' | tail -12

echo
echo "=== open-sse dir (client shim?) ==="
docker exec 9router sh -c 'ls -la /app/open-sse | head -12' 2>&1
docker exec 9router sh -c 'grep -rhoE "x-opencode-[a-z-]+|opencode/[0-9.]+|attest[a-zA-Z]*" /app/open-sse 2>/dev/null | sort -u | head -10' 2>&1
