Skip to content

feat: add Chat module with TanStack AI streaming and RAG#95

Merged
antosubash merged 6 commits intomainfrom
feature/modest-dhawan
Apr 8, 2026
Merged

feat: add Chat module with TanStack AI streaming and RAG#95
antosubash merged 6 commits intomainfrom
feature/modest-dhawan

Conversation

@antosubash
Copy link
Copy Markdown
Owner

Summary

New user-facing Chat module layered on top of the existing Agents framework — conversations UI, multi-turn history, automatic RAG augmentation, and streaming replies over the @tanstack/ai SSE protocol.

  • Backend (modules/Chat): Contracts + impl + DbContext with per-user Conversation/ChatMessage persistence, IChatContracts for cross-module use, ChatPermissions (View/Create/ManageAll), seven REST endpoints for CRUD + message history, one SSE streaming endpoint.
  • Streaming wire format: the /api/chat/conversations/{id}/stream endpoint emits TanStack content/done/error chunks. Mid-stream LLM failures are delivered as error frames and any partial assistant text is still persisted.
  • Frontend (Pages/Conversation.tsx): uses useChat from @tanstack/ai-react with fetchServerSentEvents; seeds initialMessages from server props. Pages/Browse.tsx lists conversations and creates new ones via an agent picker.
  • Framework (framework/SimpleModule.Agents): AgentChatRequest gains an optional History collection; PrepareAgentCallAsync replays prior turns so multi-turn conversations have context. Backwards-compatible (default null) — existing Agents-module callers unaffected.
  • Shared test infra (tests/SimpleModule.Tests.Shared): registers ChatDbContext so integration tests can hit the Chat module through the real HTTP pipeline.

Test plan

  • dotnet build template/SimpleModule.Host — 0 errors (source generator discovers [Module("Chat")], no SM00xx diagnostics)
  • dotnet test modules/Chat/tests/SimpleModule.Chat.Tests74 tests passing
    • Unit (47): ChatServiceTests (29), TanStackDtoSerializationTests (6), ConversationIdTests + ChatMessageIdTests (7), AgentHistoryReplayTests (5 — proves framework history replay with a fake IChatClient)
    • Integration (27): ChatEndpointTests (17 — CRUD over HTTP, auth, permission, multi-user isolation), ChatStreamingEndpointTests (10 — SSE wire format parsing, persistence, history forwarding, error frames)
  • dotnet test modules/Products/tests/SimpleModule.Products.Tests — 39/39 still passing (sanity-check the shared-factory edits)
  • Manual: dotnet run --project template/SimpleModule.Host, navigate to /chat, pick an agent, send a message and confirm the response streams token-by-token
  • Manual: with a RAG-enabled agent, verify retrieved context is surfaced in replies (uses the agent definition's existing EnableRag/RagCollectionName)

Notes

  • No attribution/codegen strings added; routes.ts regeneration is the only auto-generated churn in the diff.
  • @tanstack/ai-react / @tanstack/ai-client are declared as ^0.1.0 in modules/Chat/src/SimpleModule.Chat/package.json — pin to the latest real version during review if needed.

New user-facing Chat module layered on top of the Agents framework:
conversations UI, multi-turn history, and automatic RAG augmentation
via the existing agent pipeline.

- Chat module (Contracts + impl + tests) with per-user conversations,
  permissions (Chat.View/Create/ManageAll), and IChatContracts for
  cross-module access
- Streaming endpoint emits the @tanstack/ai SSE protocol
  (content/done/error chunks); Conversation.tsx uses useChat via
  fetchServerSentEvents
- Graceful mid-stream error handling: LLM failures surface as TanStack
  error chunks and partial replies are still persisted
- Framework: AgentChatRequest gains optional History; PrepareAgentCallAsync
  replays prior turns so multi-turn conversations have context
- Shared test factory registers ChatDbContext
- 74 tests (unit + HTTP integration + streaming wire-format)
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Apr 8, 2026

Deploying simplemodule-website with  Cloudflare Pages  Cloudflare Pages

Latest commit: 16c1a8a
Status: ✅  Deploy successful!
Preview URL: https://e1702273.simplemodule-website.pages.dev
Branch Preview URL: https://feature-modest-dhawan.simplemodule-website.pages.dev

View logs

@antosubash antosubash merged commit 6945595 into main Apr 8, 2026
5 checks passed
@antosubash antosubash deleted the feature/modest-dhawan branch April 8, 2026 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant