#!/usr/bin/env bash
#
# Records the narrated Lowell tour end to end.
#
# web/tour/build.sh # cedar if reachable, else macOS 'say'
# web/tour/build.sh --engine=openai # insist on cedar; fail if unavailable
#
# Expects jac-serve on :8787 and `npm run dev` on :3000. The demo repos are
# re-seeded first so the tour always narrates the same repository state.
set -euo pipefail
cd "$(dirname "$0")/.."
API="${TOUR_API:-http://localhost:8787}"
BASE="${TOUR_BASE:-http://localhost:3000}"
echo "==> checking services"
curl -sf "$API/api/health" >/dev/null || { echo "jac-serve not answering on $API"; exit 1; }
curl -sf -o /dev/null "$BASE" || { echo "next dev not answering on $BASE"; exit 1; }
echo "==> seeding demo state (ignored if already seeded)"
curl -s -o /dev/null -X POST "$API/api/demo" || true
echo "==> narrating"
node tour/narrate.mjs "$@"
echo "==> recording"
node tour/tour.mjs
echo "==> muxing"
node tour/mux.mjs
echo
echo "done: web/tour/out/lowell-tour.mp4"