A small Next.js web UI for demonstrating the hackbot-api.
It lets you:
- Trigger the
bug-fixagent by entering a Bugzilla bug ID (plus optional model / max-turns / effort). - Observe state — the dashboard and the run detail page poll the API and
show each run's status live (
pending → running → succeeded / failed / timed_out). - Read the result on completion — the agent's summary findings (rendered as an "Agent log" pane when a free-text log/output field is present) and the artifacts written to the results bucket, each a download link (the browser is redirected to a short-lived signed GCS URL).
This is a demo surface, not a system of record. It has no list-runs endpoint upstream, so the browser remembers the runs you triggered in
localStorage.
Browser ──> Next.js route handlers (/api/*) ──> hackbot-api (X-API-Key)
└─ better-auth (Google, @mozilla.com only)
The hackbot-api key never reaches the browser: every call goes through a
server-side route handler in app/api/* that injects the X-API-Key header
(see lib/hackbot.ts). Those handlers also re-validate the session.
Sign-in is Google OAuth via better-auth, limited
to @mozilla.com accounts:
- No database — fully stateless.
lib/auth.tsconfigures better-auth with nodatabase, so the session lives entirely in a signed + encrypted (JWE) cookie and the server never queries any store to validate it. The only shared state isBETTER_AUTH_SECRET. See better-auth's stateless session docs. - The
@mozilla.comrestriction is enforced in two mode-independent layers: the Google provider'smapProfileToUserrejects non-Mozilla identities during the OAuth callback (before a session is issued), andgetAuthedEmail()(lib/session.ts) re-checks the domain on every proxy request.hd: "mozilla.com"is also passed to Google as a UI hint. middleware.tsredirects unauthenticated visitors to/login(and returns401JSON for/api/*).
| UI action | hackbot-api call |
|---|---|
| Trigger a run | POST /agents/bug-fix/runs |
| Poll run state | GET /runs/{run_id} |
| Download artifact | GET /runs/{run_id}/artifacts/{path} † |
| (available) | GET /agents |
-
Install dependencies:
npm install
-
Configure the environment:
cp .env.example .env.local # fill in HACKBOT_API_URL, HACKBOT_API_KEY, # BETTER_AUTH_SECRET, GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET
For the Google OAuth client, add this authorized redirect URI:
http://localhost:3000/api/auth/callback/google(No database setup or migration step — auth is stateless.)
-
Run it:
npm run dev
Open http://localhost:3000 — you'll be redirected to
/login.
Run from the repository root; the Dockerfile builds from the root context.
docker build -t hackbot-ui -f services/hackbot-ui/Dockerfile .
docker run -p 3000:3000 --env-file services/hackbot-ui/.env.local hackbot-uiThe image uses Next.js output: "standalone".
Stateless auth makes this Cloud Run-friendly out of the box: sessions are
self-contained cookies, so they survive scale-to-zero and work across any number
of instances — as long as every instance shares the same BETTER_AUTH_SECRET
(set it as a secret/env var on the service). No database to provision.
Use ./deploy.sh (build → push to Artifact Registry → gcloud run deploy). It
keeps secrets in Secret Manager and reads everything else from env vars. The
service runs as a dedicated least-privilege service account
(hackbot-ui-run@<project>) that the script creates and grants
secretmanager.secretAccessor on just the three secrets it reads — no other GCP
permissions (it reaches hackbot-api over HTTPS with the API key, not via IAM).
The hackbot-api key reuses the existing shared external-api-key secret
(override with API_KEY_SECRET=...), so only two UI-specific secrets need
creating: hackbot-ui-auth-secret and hackbot-ui-google-secret.
# one-time: enable APIs + create the two UI secrets (see the header of deploy.sh).
# The deployer needs run.admin + iam.serviceAccountUser on the new SA.
# first deploy (no BETTER_AUTH_URL yet — Cloud Run assigns the URL):
PROJECT=my-proj REGION=us-central1 \
HACKBOT_API_URL=https://hackbot-api-xxxx.run.app \
GOOGLE_CLIENT_ID=xxx.apps.googleusercontent.com \
./deploy.sh
# then: add <printed-url>/api/auth/callback/google to the Google OAuth client,
# and re-run with BETTER_AUTH_URL=<printed-url> to finalize.HACKBOT_API_URL is the hackbot-api's public Cloud Run URL; HACKBOT_API_KEY
must match its X-API-Key.
| Variable | Purpose |
|---|---|
HACKBOT_API_URL |
Base URL of hackbot-api (no trailing slash) |
HACKBOT_API_KEY |
Value for the X-API-Key header (server-side) |
WEAVE_PROJECT |
Weave entity/project for run trace links |
BETTER_AUTH_URL |
Public base URL of this app |
BETTER_AUTH_SECRET |
Session signing secret (openssl rand -base64 32) |
GOOGLE_CLIENT_ID |
Google OAuth client ID |
GOOGLE_CLIENT_SECRET |
Google OAuth client secret |