Skip to content

refactor: tool-based RAG UI with block-based rendering - #1047

Merged
nerualauren merged 1 commit into
StampyAI:masterfrom
nerualauren:tool-rag-ui
Apr 4, 2026
Merged

nerualauren merged 1 commit into
StampyAI:masterfrom
nerualauren:tool-rag-ui

Conversation

@nerualauren

@nerualauren nerualauren commented Apr 2, 2026 •

Copy link
Copy Markdown

Note: This PR was assembled and reviewed by Claude Code. Lauren has reviewed the design and conversation but has not yet read the full diff line-by-line. [edit: have now read the full diff]

Companion PR to StampyAI/stampy-chat#204 -- updates the chat UI to support the new tool-based RAG pipeline.

Summary

  • Block-based rendering: thinking, tool_use+tool_result (merged into single collapsible), text blocks
  • Turn-based SSE protocol: handles new turn events carrying tool results alongside existing streaming/thinking events
  • Citations from tool results: extracted from tool_result.ui_output blocks instead of a separate citations SSE event
  • Cross-turn citation resolution: priorCitations accumulated across conversation turns
  • Markdown + KaTeX: react-markdown with remark-math/rehype-katex for math rendering
  • Memoized CitationMarkdown: fixes perf issue where withCitationProcessing recreated component types every render, causing React unmount/remount flicker during streaming
  • Tool display: friendly names ("Searched articles", "Viewed full article") in collapsible details with request/response
  • Model list: updated to dateless Anthropic IDs (claude-sonnet-4-6, claude-opus-4-6, etc.)
  • CHATBOT_URL: production default with automatic localhost detection for dev
  • Payload limit: raised to 200KB for block-structured history with tool results

Test plan

  • Local dev: chat works with tool calls visible in collapsible details
  • Citations render correctly with clickable reference links
  • Multi-turn conversations preserve citation numbering
  • Thinking blocks show animated ellipsis while active, "Thoughts" when done
  • Math expressions render via KaTeX
  • No flicker during streaming (CitationMarkdown memoization)
  • Production build hits chat.stampy.ai, local dev hits localhost:3001

🤖 Generated with Claude Code

Update chat UI to support the new tool-based RAG pipeline from
stampy-chat (StampyAI/stampy-chat#204).

- Block-based rendering: thinking, tool_use+tool_result (merged), text
- Turn-based SSE protocol: handle 'turn' events with tool results
- Citations extracted from tool_result ui_output blocks
- Cross-turn citation reference resolution via priorCitations
- Markdown rendering with react-markdown, KaTeX math support
- Memoized CitationMarkdown component (avoids recreating component
  types per render causing unmount/remount flicker)
- Tool calls displayed with friendly names in collapsible details
- Parallel tool_use blocks matched to tool_results by id (not adjacency)
- Model list updated to dateless Anthropic IDs (claude-sonnet-4-6 etc.)
- CHATBOT_URL: production default with localhost auto-detection for dev
- Payload size limit raised to 200KB for block-structured history
- Glossary injection skips pre and details elements (prevents corrupting
  tool result XML display)
- Removed: useIsMobile/mobile prop (unused), DOMPurify (replaced by
  react-markdown's React-native rendering)
- Kept upstream's useGlossaryInjection and glossary popup support
import {Link} from '@remix-run/react'
import MarkdownIt from 'markdown-it'
import DOMPurify from 'dompurify'
import Markdown from 'react-markdown'

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switching to react-markdown for the chatbot for flexibility. also makes it reasonably easy to toss in katex (math rendering), which we want anyway.

Comment thread package.json
"isbot": "^5.1.28",
"katex": "^0.16.23",
"lodash": "^4.17.21",
"markdown-it": "^14.1.0",

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

markdown-it isn't going away because it's used in articles. I poked claude several times about maybe could we just do one or the other, but the conclusion ended up being "well, maybe, but the bottleneck is human testing effort, and react-markdown handles more of what we need for chatbot ui".

@Algon-33
Algon-33 self-requested a review April 2, 2026 23:55
@Algon-33

Algon-33 commented Apr 3, 2026 •

Copy link
Copy Markdown
Collaborator

Oh crud, for some reason I didn't merge this when talking to @nerualauren earlier! Anyway, I think lauren should merge this since apparently it needs to be done at the same time as another PR lauren has got otherwise things will break.

@nerualauren
nerualauren merged commit cbcdf77 into StampyAI:master Apr 4, 2026
1 check passed
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.

3 participants