ubiquitous-invention/plans/Plan-daily-driver-finish/Epic-shipping-the-shell
Randall Stillwell a1e6c863d5 feat(web): wire AI chat page to streaming /api/chat handler
Path-A task 3/5. Replaces the setTimeout mock that returned the literal
"Full AI integration is coming soon!" string with a real streaming
provider call.

* apps/web/app/api/chat/route.ts (new): POST handler that runs the
  same auth + resolveWorkspace pipeline workspaceProcedure uses, then
  streams a response from streamText().toDataStreamResponse(). Maps
  resolveWorkspace's TRPCError codes to HTTP status (401/403/404/400).
  Returns a structured 503 with a human-readable hint when
  OPENAI_API_KEY is unset, so the misconfiguration is surfaced rather
  than masked by a fake stream.

* apps/web/app/(app)/[workspaceSlug]/ai/page.tsx: replace the local
  message-state + setTimeout placeholder with useChat from
  @ai-sdk/react. workspace slug is sent on every request body so the
  server can enforce tenant scoping. Adds a ChatErrorBanner that
  parses the JSON error body the route emits and renders amber for
  the "unavailable" case, destructive for other failures.

* apps/web/package.json: pull in @ai-sdk/react as a direct dep
  (previously only transitive via `ai`).

The existing aiRouter.chat tRPC mutation is left intact — it powers
the right-panel command palette via the non-streaming generateText
path, and rebuilding that as streaming was outside the scope of
making the dedicated chat page usable.

Provider selection still flows from env per packages/ai conventions:
OPENAI_API_KEY gates availability, OPENAI_BASE_URL lets operators
route through Ollama on CT 108 transparently, OPENAI_MODEL overrides
the default gpt-4o-mini.

`pnpm lint && pnpm type-check` clean. Closes
plans/Plan-daily-driver-finish/Epic-shipping-the-shell/
Task-wire-ai-chat-to-trpc.md.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-02 00:23:21 -05:00
..
Epic-shipping-the-shell.md plans: scaffold daily-driver-finish, saas-hardening, agent-coordination 2026-06-01 23:52:22 -05:00
Task-fix-lint-and-shared-types.md chore(lint+types): green pnpm lint && pnpm type-check from a clean clone 2026-06-02 00:11:52 -05:00
Task-pick-workspace-landing-route.md plans: scaffold daily-driver-finish, saas-hardening, agent-coordination 2026-06-01 23:52:22 -05:00
Task-smoke-test-collab-editor.md plans: scaffold daily-driver-finish, saas-hardening, agent-coordination 2026-06-01 23:52:22 -05:00
Task-wire-ai-chat-to-trpc.md feat(web): wire AI chat page to streaming /api/chat handler 2026-06-02 00:23:21 -05:00
Task-wire-workspace-home-dashboard.md feat(web): wire workspace-home dashboard to real tRPC queries 2026-06-02 00:17:29 -05:00