Skip to content

Conversation

devin-ai-integration[bot]
Copy link
Contributor

Description

Adds a custom "Ask AI: {query}" result option that appears as the first item in Kapa search results. When clicked, it opens the AskAI modal with the user's search query pre-filled. This replaces the built-in data-search-show-ask-ai-cta option to prevent unwanted Enter key triggering.

Custom Ask AI result

Key behaviors:

  • ✅ Custom result appears first in all search results
  • ✅ Displays "Ask AI: {query}" with the user's search text
  • ✅ Clicking opens AskAI modal with query pre-filled
  • ✅ Uses tabindex="-1" so Enter key skips over it (only explicit clicks work)

Implementation Details

  • Hooks into Kapa's onSearchResultsCompleted event to inject custom DOM element
  • Accesses Kapa widget via Shadow DOM using getElementById('kapa-widget-container')
  • Finds results container heuristically (div with >5 anchor children)
  • Uses 100ms setTimeout to ensure Kapa has finished rendering

Human Review Checklist

⚠️ High Priority Items:

  • Shadow DOM access pattern - Verify this approach is acceptable given fragility if Kapa changes internals
  • DOM selection heuristics - Review the "div with >5 anchor children" logic for edge cases
  • Styling consistency - Confirm inline styles match design system and are responsive
  • Error handling - Consider if silent failures are acceptable or if logging/fallbacks needed

Standard Items:

  • Feature works as expected in different browsers
  • No performance impact from DOM manipulation
  • Event listeners properly cleaned up
  • Accessibility considerations (role, tabindex usage)

Questions?

This PR implements the custom Ask AI search result requested by @xhuang-statsig in Devin session.

The main tradeoff is implementation fragility (Shadow DOM manipulation) vs. user experience (avoiding unwanted Enter key behavior). The current approach prioritizes UX as requested.

- Add onSearchResultsCompleted event handler to inject custom 'Ask AI' result
- Custom result appears as first option in search results with user's query
- Clicking opens AskAI modal with search query pre-filled
- Uses tabindex='-1' to prevent Enter key triggering (only explicit click works)
- Accesses Kapa widget via Shadow DOM using getElementById('kapa-widget-container')
- Replaces built-in data-search-show-ask-ai-cta to avoid unwanted Enter behavior
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@jasonwzm
Copy link
Member

jasonwzm commented Sep 30, 2025

🚀 Deployed on https://68dc95702dcba98fb973cb64--cozy-fox-0defec.netlify.app

@jasonwzm jasonwzm temporarily deployed to pull request September 30, 2025 22:04 Inactive
- Replace SVG info icon with ✨ sparkles emoji (U+2728)
- Auto-execute query when custom result is clicked
- Maintain focus on textarea input after query execution
- Add multiple fallback selectors for submit button detection
- Query now executes automatically instead of just pre-filling
@jasonwzm jasonwzm temporarily deployed to pull request September 30, 2025 22:23 Inactive
- Target mantine-ActionIcon-root with data-variant='filled' as primary selector
- Matches exact button class provided by user feedback
- Enables proper auto-execution when clicking custom Ask AI result
@jasonwzm jasonwzm temporarily deployed to pull request September 30, 2025 22:38 Inactive
- Focus search input field (mantine-TextInput-input) when Kapa modal opens
- 100ms delay ensures modal DOM is ready before focusing
- Enhances keyboard accessibility for cmd+K shortcut users
@jasonwzm jasonwzm temporarily deployed to pull request September 30, 2025 22:52 Inactive
- Add border-radius and proper hover/focus styling to match other results
- Enable keyboard navigation with tabindex='0'
- Add Enter/Space key activation support
- Include focus outline with box shadow for accessibility
- Enhanced hover effects with subtle box shadow
@jasonwzm jasonwzm temporarily deployed to pull request September 30, 2025 23:17 Inactive
@jasonwzm jasonwzm temporarily deployed to pull request September 30, 2025 23:51 Inactive
- Change element from div to anchor tag for proper keyboard navigation
- Use border instead of box-shadow for rounded focus outline
- Change default background from gray to transparent
- Refactor click handler to support both click and keyboard activation
@jasonwzm jasonwzm temporarily deployed to pull request October 1, 2025 00:16 Inactive
- Enables arrow key navigation to custom Ask AI result
- Allows Enter/Space key activation when focused
- Focus event listeners will apply rounded blue border outline
@jasonwzm jasonwzm temporarily deployed to pull request October 1, 2025 00:23 Inactive
- Use MutationObserver to watch tabindex changes instead of focus events
- Apply rounded focus styling when tabindex='0' (Kapa's focus indicator)
- Add document-level keydown listener for Enter/Space activation
- Maintain rounded corners (border-radius: 8px) in focus outline
- Ensure proper cleanup of event listeners and observers
@jasonwzm jasonwzm temporarily deployed to pull request October 1, 2025 00:31 Inactive
- Add immediate tabindex check to apply focus styles on initial render
- Move keydown listener from document to Shadow DOM for proper event capture
- Ensures focus styling appears when element has tabindex='0'
- Fixes Enter key activation inside Shadow DOM
@jasonwzm jasonwzm temporarily deployed to pull request October 1, 2025 00:43 Inactive
@jasonwzm jasonwzm temporarily deployed to pull request October 1, 2025 01:17 Inactive
- Add e.target check to keydown handler to only activate when Space/Enter
  is pressed directly on the custom result element
- Prevents unintended activation when typing in search input field
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