ubiquitous-invention/apps/web/app/(app)/[workspaceSlug]
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
..
[projectId] multi-tenancy: promote workspaces to top-level table 2026-05-06 23:02:55 -05:00
ai feat(web): wire AI chat page to streaming /api/chat handler 2026-06-02 00:23:21 -05:00
docs multi-tenancy: promote workspaces to top-level table 2026-05-06 23:02:55 -05:00
forms multi-tenancy: promote workspaces to top-level table 2026-05-06 23:02:55 -05:00
planner multi-tenancy: promote workspaces to top-level table 2026-05-06 23:02:55 -05:00
settings multi-tenancy: promote workspaces to top-level table 2026-05-06 23:02:55 -05:00
teams multi-tenancy: promote workspaces to top-level table 2026-05-06 23:02:55 -05:00
whiteboards multi-tenancy: promote workspaces to top-level table 2026-05-06 23:02:55 -05:00
layout.tsx feat: Full project management application scaffold 2026-03-26 22:39:16 -05:00
page.tsx feat(web): wire workspace-home dashboard to real tRPC queries 2026-06-02 00:17:29 -05:00