group v4 routes with fastify plugins

Merged
MO
8mo ago
+278-77

why

This splits the v4 route groups into real Fastify plugins so each group owns its own registration and error boundary. It removes the path-sniffing logic from server.ts and makes the v4 stub server a cleaner base for future route work.

what changed

page and browsersession now register through Fastify plugins instead of array loops in server.ts, and each plugin has its own encapsulated error handler. server.ts is reduced to composing the two v4 plugins under /v4.

test plan

  • pnpm --filter @browserbasehq/stagehand-server-v4 lint
  • pnpm --filter @browserbasehq/stagehand-server-v4 build

Summary by cubic

Grouped v4 page and browsersession routes into Fastify plugins under /v4, each with its own error boundary and OpenAPI tag. Added shared helpers for tagging and typed error normalization to simplify server.ts and complete STG-1610.

  • Refactors
    • Introduced pageRoutesPlugin and browserSessionRoutesPlugin; registered at /v4.
    • Added shared pluginUtils (withTag, normalizePluginError) used by both plugins.
    • Plugins tag routes (page, browserSession) and return typed validation/serialization errors via buildErrorResponse and buildBrowserSessionErrorResponse; applied tags across openapi.v4.yaml.
    • Simplified the app-level error handler to a generic fallback; removed path sniffing and route array loops from server.ts.