Same proxy as netlify/functions/ai.mjs, rebuilt as a standalone Bun service on
the CVM host so AI calls stop spending Netlify compute/bandwidth credits and
the sats-paid Routstr key lives on our box.
- ai-proxy/server.ts: Bun.serve on 127.0.0.1:8787 — NIP-98 + Pro gate, model
allowlist, per-IP throttle, /api/ai + /api/ai/status. Own tsconfig
(typecheck:ai in npm test); eslint-ignored like cvm-server.
- ai-proxy/{package.json,.env.example,skatespots-ai.service,Caddyfile,DEPLOY.md}.
- scripts/deploy-ai-proxy.sh (npm run deploy:ai): scp + bun install + unit +
restart, mirroring deploy-cvm.sh.
- Client: one place decides the AI base, src/lib/sasquatchAi.ts (also the NIP-98
u tag). Defaults unchanged (/api/ai on Netlify); set VITE_SASQUATCH_AI_BASE to
move it. Fully reversible.
Deployed and verified on the host: /api/ai/status returns the live Routstr
balance. Public TLS (DNS + Caddy) is the remaining step before switching the app
over, so no client behaviour changes yet.
59 lines
2.2 KiB
Bash
Executable file
59 lines
2.2 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
#
|
|
# Deploy the SkateSpots AI proxy to the CVM host (same box as the CVM server).
|
|
#
|
|
# It is the same class of service as deploy-cvm.sh: a Bun process under systemd,
|
|
# reachable only via Caddy (TLS) on the public side. Config/host come from
|
|
# ~/.config/skatespots/cvm.env (never committed).
|
|
#
|
|
# npm run deploy:ai # or: bash scripts/deploy-ai-proxy.sh
|
|
# bash scripts/deploy-ai-proxy.sh --logs
|
|
set -euo pipefail
|
|
|
|
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
|
|
CONF="${HOME}/.config/skatespots/cvm.env"
|
|
if [[ -f "$CONF" ]]; then
|
|
# shellcheck disable=SC1090
|
|
source "$CONF"
|
|
fi
|
|
|
|
: "${CVM_HOST:?Set CVM_HOST (e.g. in ~/.config/skatespots/cvm.env) — the host is never committed}"
|
|
CVM_SSH_KEY="${CVM_SSH_KEY:-$HOME/.ssh/skatespots-new}"
|
|
AI_DIR="${AI_DIR:-/home/ubuntu/skatespots-ai}"
|
|
AI_SERVICE="${AI_SERVICE:-skatespots-ai}"
|
|
|
|
SSH=(ssh -i "$CVM_SSH_KEY" -o BatchMode=yes -o ConnectTimeout=12 "$CVM_HOST")
|
|
|
|
if [[ "${1:-}" == "--logs" ]]; then
|
|
"${SSH[@]}" "journalctl -u $AI_SERVICE -n 40 --no-pager"
|
|
exit 0
|
|
fi
|
|
|
|
echo "→ Ensuring $AI_DIR exists"
|
|
"${SSH[@]}" "mkdir -p $AI_DIR"
|
|
|
|
echo "→ Uploading ai-proxy/{server.ts,package.json,skatespots-ai.service}"
|
|
scp -i "$CVM_SSH_KEY" -o BatchMode=yes \
|
|
"$REPO_ROOT/ai-proxy/server.ts" \
|
|
"$REPO_ROOT/ai-proxy/package.json" \
|
|
"$REPO_ROOT/ai-proxy/skatespots-ai.service" \
|
|
"$CVM_HOST:$AI_DIR/"
|
|
|
|
echo "→ bun install"
|
|
"${SSH[@]}" "cd $AI_DIR && ~/.bun/bin/bun install --silent 2>&1 | tail -3 || true"
|
|
|
|
echo "→ Installing the unit and (re)starting $AI_SERVICE"
|
|
"${SSH[@]}" "sudo cp $AI_DIR/skatespots-ai.service /etc/systemd/system/ \
|
|
&& sudo systemctl daemon-reload \
|
|
&& sudo systemctl enable --now $AI_SERVICE >/dev/null 2>&1 || true; \
|
|
sudo systemctl restart $AI_SERVICE \
|
|
&& sleep 2 && echo \"active: \$(systemctl is-active $AI_SERVICE)\""
|
|
|
|
echo "→ Local health check (through the service, on the host)"
|
|
"${SSH[@]}" "curl -s -o /dev/null -w 'status endpoint: %{http_code}\n' -X POST http://127.0.0.1:8787/api/ai/status || true"
|
|
|
|
echo "→ Recent log:"
|
|
"${SSH[@]}" "journalctl -u $AI_SERVICE -n 15 --no-pager | tail -6"
|
|
|
|
echo "✅ AI proxy deployed. Public TLS is served by Caddy — see ai-proxy/DEPLOY.md."
|