#!/usr/bin/env bash
# Real demos for P043 "Google AI Studio Will Finally Make Sense After This". Runs on the Mac (Docker Desktop):
# the Gemini API key lives only on the Mac, never on render01.
# One container, ce-p043-laptop: a stock Ubuntu 24.04 with curl, jq and Google's Gen AI SDK (lab/Dockerfile),
# Ana's request files in ~/shop. Every command shown is typed into a real interactive bash in a pty
# (demo_driver.py) and sent to the real Gemini API.
# Two keys, never printed (the driver refuses to save any output that contains either):
#   GEMINI_API_KEY  the key of our paid project ("My First Project", billing on; owner OK 2026-11-06)
#   FREE_KEY        the free-tier key of the "Default Gemini Project" (the project AI Studio makes for new users),
#                   used for one request only, to show the free tier's daily limit
set -euo pipefail
cd "$(dirname "$0")"
P=ce-p043
KEYS="$(git rev-parse --show-toplevel)/.gemini_keys.json"
[ -f "$KEYS" ] || KEYS="$HOME/cloudexplainers/.gemini_keys.json"
cleanup() { docker rm -f $P-laptop >/dev/null 2>&1 || true; }
cleanup
[ -n "${KEEP:-}" ] || trap cleanup EXIT
docker build -q -t $P-laptop lab >/dev/null
key() { python3 -c "import json,sys; print([k for k in json.load(open(sys.argv[1]))['projects'][sys.argv[2]]['keys'] if k['display_name'] == sys.argv[3]][0]['key_string'])" "$KEYS" "$1" "$2"; }
GEMINI_API_KEY=$(key project-593e5bf6-d8b6-4ffd-878 "Gemini API Key")
FREE_KEY=$(key gen-lang-client-0388842080 "Default Gemini API Key")
export GEMINI_API_KEY FREE_KEY
docker run -d --name $P-laptop --hostname laptop -e GEMINI_API_KEY -e FREE_KEY $P-laptop sleep infinity >/dev/null
python3 - "$P" < demo_driver.py
