#!/bin/bash
export LC_ALL=C
echo "=== NODE (undici fetch) — same stack as 9router ==="
docker exec 9router node -e '
const body = JSON.stringify({
  model: "mimo-v2.6-flash-free",
  messages: [{role:"user", content:"hi"}],
  stream: true
});
(async () => {
  const t0 = Date.now();
  try {
    const r = await fetch("https://opencode.ai/zen/v1/chat/completions", {
      method: "POST",
      headers: {
        "content-type": "application/json",
        "accept": "text/event-stream",
        "x-opencode-client": "desktop",
        "user-agent": "opencode/1.18.31"
      },
      body
    });
    const txt = await r.text();
    console.log("  HTTP", r.status, Date.now()-t0+"ms");
    console.log("  body:", txt.slice(0,300));
  } catch (e) {
    console.log("  ERR", e.message, Date.now()-t0+"ms");
  }
})();' 2>&1 | head -8

echo
echo "=== NODE via proxy pool (undici ProxyAgent) ==="
docker exec 9router node -e '
const { ProxyAgent } = require("undici");
const dispatcher = new ProxyAgent("http://172.19.0.1:20808");
const body = JSON.stringify({model:"mimo-v2.6-flash-free",messages:[{role:"user",content:"hi"}],stream:true});
(async () => {
  const t0 = Date.now();
  try {
    const r = await fetch("https://opencode.ai/zen/v1/chat/completions", {
      method: "POST", dispatcher,
      headers: {"content-type":"application/json","accept":"text/event-stream","x-opencode-client":"desktop"},
      body
    });
    const txt = await r.text();
    console.log("  HTTP", r.status, Date.now()-t0+"ms");
    console.log("  body:", txt.slice(0,300));
  } catch (e) { console.log("  ERR", e.message); }
})();' 2>&1 | head -8
