#42

Route Focus and Smart Compose through AI Gateway

MergedstylesshOwnermerged intofrom

Summary

  • route Focus classification through typesafe-ai/jev via Vercel AI Gateway
  • evaluate inbox summaries first, then refine only low-confidence threads with bounded message content
  • route Smart Compose through the same Redakt-managed Gateway and simplify AI consent/settings
  • remove legacy provider-key handling, update privacy/deployment docs, and purge stored legacy key fields

Verification

  • corepack pnpm test (169 passing)
  • corepack pnpm exec eslint ...
  • corepack pnpm exec next typegen && corepack pnpm exec tsc --noEmit
  • corepack pnpm build
  • live Jev evaluation smoke test
  • live structured Smart Compose smoke test through Gateway
  • browser verification of AI settings and Focus in demo mode

Deployment

AI_GATEWAY_API_KEY is configured on the Railway Redakt production and staging services. This PR does not trigger a deployment.

Activity

5
stylessh merged commit c2b5709 into main2mo ago
Git branch
stylessh deleted stylessh/jev-focus-gateway branch2mo ago
mikeyreviewed2mo ago
mikey2mo ago

Summary

Focus and Smart Compose are cleanly re-plumbed onto AI Gateway (typesafe-ai/jev via experimental_evaluate, Gemini Flash-Lite via generateText), and the BYOK removal is thorough — no dangling references to the old provider/credential types, the consent version bump correctly forces re-consent, the data-purge migration is a straightforward one-way null-out, and privacy/terms copy was updated to match the new data flow. The two-phase Focus design (cheap summary pass, detail refinement only for confidence < 0.72) and the evaluate()/generateText() usage both match the documented AI Gateway API shapes.

One correctness regression in lib/ai/compose.ts (see inline comment) should block merge: the JSON schema sent to the model no longer bounds block/run/text sizes, but the runtime validator still rejects output that exceeds the old bounds, so legitimate Smart Compose output can now start failing with a user-facing "invalid writing suggestion" 502.

Two minor, non-blocking follow-ups:

  • lib/db/schema.ts still declares provider, model, encryptedApiKey, apiKeyHint columns on aiSettings. The migration nulls the data but the columns and their notNull().default(...) aren't dropped — dead schema surface after this PR removes every reader/writer of those fields except the purge migration itself.
  • app/api/settings/ai/route.ts's DELETE handler has no remaining caller now that the "Remove API key" dialog was removed from components/settings/ai-settings.tsx. Not broken (it still resets consent/enabled meaningfully), just unreachable from the UI — worth a follow-up decision on whether to keep it as a documented API or drop it.

Tests, lint, typecheck, and build are reported green per the PR description; I did not re-run them.

Branch stylessh/jev-focus-gateway has been deleted.