#!/bin/bash
# Simulate browser: chat stream + TTS call
echo "=== Chat Stream Test ==="
START=$(date +%s)
# Send chat request and capture response
curl -s --max-time 30 \
  http://localhost:9090/api/proxy/chat \
  -H 'Content-Type: application/json' \
  -d '{"messages":[{"role":"user","content":"Say hi in one sentence."}],"stream":true}' \
  -o /tmp/chat_stream.txt 2>&1
EXIT=$?
END=$(date +%s)
echo "curl exit: $EXIT, took: $((END-START))s"
echo "Last 5 lines of stream:"
tail -5 /tmp/chat_stream.txt
echo ""
echo "Has [DONE]:"
grep -c "DONE" /tmp/chat_stream.txt
echo ""

echo "=== Now TTS call ==="
curl -s -w '\nHTTP: %{http_code} Size: %{size_download}\n' \
  -o /tmp/tts_after_chat.wav \
  http://localhost:9090/api/proxy/tts \
  -H 'Content-Type: application/json' \
  -d '{"input":"Hello there!","voice":"Vivian","language":"en","speed":1.0}'

echo "=== Sidecar health ==="
curl -s http://localhost:9090/api/tts/sidecar/health
echo ""
