Skip to content

feat: Replace Kapa AI with first-party docs-mcp chat#17632

Draft
MathurAditya724 wants to merge 13 commits intomasterfrom
MathurAditya724/feat/replace-kapa-with-ask-ai
Draft

feat: Replace Kapa AI with first-party docs-mcp chat#17632
MathurAditya724 wants to merge 13 commits intomasterfrom
MathurAditya724/feat/replace-kapa-with-ask-ai

Conversation

@MathurAditya724
Copy link
Copy Markdown
Member

DESCRIBE YOUR PR

Replace the third-party Kapa AI widget with a first-party AI chat modal powered by the docs-mcp Cloudflare Worker (getsentry/cli-init-api).

What changed:

  • Removed the Kapa AI widget (external JS bundle, CSS, TypeScript types, CSP entries)
  • Added a custom AskAiModal chat component with streaming responses, multi-turn conversation, markdown rendering, and example questions
  • Added AskAiProvider React context to manage modal state
  • Rewired all 4 existing Ask AI trigger points (desktop search bar button, mobile header button, inline "Ask Sentry about [query]" search result, ?askAI=true URL deep link) to use the new modal
  • Updated CSP: removed widget.kapa.ai and kapa-widget-proxy, added docs-mcp.getsentry.workers.dev

Why:

  • Full control over the AI experience (prompt, model, answer quality)
  • No third-party JS bundle loaded (faster page load)
  • Uses our own docs.sentry.io .md exports for retrieval (always up-to-date)
  • Can cite specific doc pages with links

Companion PR: https://github.com/getsentry/cli-init-api/pull/124 (adds POST /api/ask endpoint to docs-mcp)

IS YOUR CHANGE URGENT?

  • Urgent deadline (GA date, etc.)
  • Other deadline
  • None: Not urgent, can wait up to 1 week+

PRE-MERGE CHECKLIST

  • Checked Vercel preview for correctness, including links
  • PR was reviewed and approved by any necessary SMEs (subject matter experts)
  • PR was reviewed and approved by a member of the Sentry docs team

Remove the third-party Kapa AI widget and replace it with a custom
AI chat modal powered by the docs-mcp Cloudflare Worker.

Changes:
- Add AskAiProvider context for modal open/close state management
- Add AskAiModal chat component with streaming, multi-turn support,
  markdown rendering, and example questions
- Rewire all Ask AI trigger points (search bar, header, inline search
  result, ?askAI=true deep link) to use the new context
- Remove Kapa widget script, CSS, TypeScript types, and CSP entries
- Add docs-mcp.getsentry.workers.dev to CSP connect-src
- Add NEXT_PUBLIC_ASK_AI_API_URL env var

Co-Authored-By: Claude <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 5, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
develop-docs Ready Ready Preview, Comment May 6, 2026 6:12pm
sentry-docs Ready Ready Preview, Comment May 6, 2026 6:12pm

Request Review

Comment thread src/components/askAi/askAiModal.tsx Fixed
…erer

Address CodeQL security finding (DOM text reinterpreted as HTML)
by replacing the string-based renderMarkdown + dangerouslySetInnerHTML
approach with a React-element-based markdown parser that produces
safe ReactNode trees directly.

Also fix broken link in AGENTS.md (remove protocol from docs-mcp
URL to prevent lychee from checking a worker with no root route).

Co-Authored-By: Claude <noreply@anthropic.com>
Comment thread src/components/askAi/askAiModal.tsx Fixed
Overhaul the chat modal design inspired by AI SDK elements:

- Full-width assistant messages with avatar icon + action bar
  (copy, retry) instead of bubble layout
- Animated streaming cursor (blinking caret) replaces bounce dots
- Polished input area with bordered container + arrow submit button
- Gradient-branded empty state with clickable suggestion cards
- Slide-up entrance animation
- Mobile-friendly: full-height on small screens, centered on desktop
- Loading spinner on submit button during streaming
- Better prose typography with refined spacing for code blocks,
  headings, lists, and links

Co-Authored-By: Claude <noreply@anthropic.com>
The modal was rendering as a sibling of <Theme>, so it didn't
inherit any Radix theme CSS variables (--gray-*, --accent-*,
--foreground, etc.) or typography styles. Move it inside <Theme>
so all the design tokens apply correctly.

Co-Authored-By: Claude <noreply@anthropic.com>
MathurAditya724 and others added 2 commits May 5, 2026 22:30
CodeQL flagged the renderInline() function for passing unsanitized AI
response text directly into anchor href attributes. Add an allow-list
check so only http:// and https:// URLs are used; anything else
renders as '#' to prevent javascript: URL injection.

Co-Authored-By: Claude <noreply@anthropic.com>
The docs-mcp.getsentry.workers.dev Cloudflare Worker only serves
/mcp and /api/ask routes — the root URL returns 404. Add it to
.lycheeignore so lychee link checker doesn't fail on URLs in plan
files and AGENTS.md that reference the worker hostname.

Co-Authored-By: Claude <noreply@anthropic.com>
Comment thread src/components/askAi/askAiModal.tsx Fixed
CodeQL's taint analysis tracks data flow from untrusted AI response
text through the ternary operator into the href attribute, flagging
it as XSS even with an allow-list check. Parse the URL through the
URL constructor and read back parsed.href to break the taint chain —
the output value is constructed from safe URL object fields rather
than copied from user-controlled input.

Co-Authored-By: Claude <noreply@anthropic.com>
Move AskAiModal inside <Theme> so it inherits all Radix CSS
variables (--gray-*, --accent-*, --foreground, etc.). Previously
it was a sibling of Theme, causing all design tokens to be missing.

Also remove 'Powered by Sentry docs' text from the input area.

Co-Authored-By: Claude <noreply@anthropic.com>
Switch backend→frontend communication from raw text to structured SSE
with typed events (text, tool_start, tool_end, error, done) so the
frontend can show tool-execution status and distinguish errors from
content.

Rewrite the Ask AI modal with:
- SSE event parsing and AbortController cancel support
- Runtime syntax highlighting via refractor + prism-sentry theme
- Per-code-block copy buttons with language labels
- Proper relative-URL handling for doc links (/platforms/... → docs.sentry.io)
- Table, blockquote, and strikethrough markdown support
- Scoped ask-ai-prose CSS replacing inline Tailwind arbitrary variants
- Stop button to cancel in-flight requests

Move prism-sentry/index.css import to root layout so token colors are
available in the modal (rendered outside [[...path]] layout).

Co-Authored-By: Claude <noreply@anthropic.com>
Comment thread src/components/askAi/askAiModal.tsx Fixed
MathurAditya724 and others added 3 commits May 6, 2026 17:43
Modal background (--gray-1) was identical to the page background in
dark mode (both #111110 in sand theme), making the modal appear
transparent. Bump to --gray-2 for modal bg, --gray-3 for input bg,
and raise all alpha borders from a3→a5 so elements are visible.

Also bump hover backgrounds from a3→a4 and inline code bg from a3→a4
to ensure interactive states are perceptible in dark mode. Increase
backdrop opacity from 50% to 60% for better page dimming.

Co-Authored-By: Claude <noreply@anthropic.com>
The alpha-based gray scale (--gray-a3 through --gray-a5) produces
nearly invisible borders and backgrounds on near-black dark mode
surfaces because the alpha values are only 7-20% opacity white.

Switch all structural borders and backgrounds to the solid gray
scale (--gray-4 through --gray-6) which has proper dark mode values
like #2a2a28, #31312e, #3b3a37 — visibly distinct from the #111110
page background.

Co-Authored-By: Claude <noreply@anthropic.com>
Tighten the empty state layout: smaller icon, less vertical padding,
narrower max-width. Add a 'Try asking' section label above the
example buttons. Buttons now have a visible bg fill (--gray-3) with
solid border (--gray-5) and hover to accent-purple border. Reduce
font sizes and gaps for a more compact, polished look.

Co-Authored-By: Claude <noreply@anthropic.com>
Replace hand-rolled buttons with Radix Button/IconButton matching
the site's established patterns (variant='ghost' color='gray' for
toolbar actions, variant='solid' for primary submit). Use Radix
ScrollArea and Separator for consistent behavior.

Fix dark mode visibility by using the solid Radix gray scale
(--gray-4/5/6) instead of the alpha scale (--gray-a3/a4/a5) which
produces near-invisible colors on dark backgrounds.

Integrate prism-sentry syntax highlighting via refractor for code
blocks, with a header bar matching the site's CodeBlock component.
Add proper prose styles via scoped CSS. Support relative doc URLs
(/platforms/... -> docs.sentry.io). Use Radix accent tokens
(--accent-9, --accent-11) for consistent theming.

Co-Authored-By: Claude <noreply@anthropic.com>
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.

2 participants