Recover server-v4 drizzle stack onto main

Merged
MO
8mo ago
+3736-692

Why

The original server-v4 stacked PRs merged into each other after STG-1614 had already merged into main, so the env/test-harness work, Drizzle foundation, and Drizzle schema/controller flow never actually reached main.

This PR recovers that full stack onto current main in one branch.

What Changed

  • cherry-picked the three stacked squash-merge commits from #1896, #1897, and #1898 onto fresh main
  • preserved the full server-v4 env/test harness cleanup, Drizzle foundation, DB smoke tests, schema/migration work, and /v4/llms controller/service/repo flow
  • added one small follow-up commit to normalize pnpm-lock.yaml against current main after applying the recovered stack

Test Plan

  • pnpm install
  • pnpm --filter @browserbasehq/stagehand-server-v4 run lint
  • pnpm --filter @browserbasehq/stagehand-server-v4 run test:unit
  • pnpm --filter @browserbasehq/stagehand-server-v4 run build
  • pnpm --filter @browserbasehq/stagehand-server-v4 run gen:openapi

Summary by cubic

Recovers the server‑v4 Drizzle stack onto main, restoring DB‑backed /v4/llms and switching the public LLMId to UUID. Adds a typed env, clean app bootstrap, and a local pglite/Postgres runtime with migrations, tests, and a simpler source‑based test harness.

  • New Features

    • Drizzle foundation with pglite default and Postgres option; new db:* scripts via drizzle-kit.
    • Fastify databasePlugin and unified DB client; app.ts bootstrap with health/readiness and Swagger/OpenAPI; env via @t3-oss/env-core.
    • Tables/relations for LLMs and Stagehand; DB‑derived Zod schemas; first migration; OpenAPI updated for UUID LLMId with strict format and pattern.
    • LLM module (repo/service/controller) backing /v4/llms; routes now delegate to the controller; browser session create uses the service and auto‑creates a system default LLM when llmId is missing.
    • Tests run from source via tsx; test server script simplified; turbo tasks cleaned up; schema cleanup (z.url()).
  • Migration

    • Run: pnpm --filter @browserbasehq/stagehand-server-v4 db:migrate.
    • Local dev uses pglite at ~/.stagehand/db/stagehand-v4. For Postgres set STAGEHAND_DB_MODE=postgres and DATABASE_URL.
    • Update clients to treat LLMId as a UUID and regenerate from openapi.v4.yaml if needed.