Skip to content

Conversation

@devin-ai-integration
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot commented Oct 20, 2025

Description

⚠️ IMPORTANT: This PR is NOT ready to merge - the custom script is not loading in the Mintlify preview deployment despite trying multiple approaches. This needs investigation before merging.

This PR attempts to add an "Ask AI" call-to-action as the first result in Mintlify search results, providing users with a seamless way to transition from search to AI-powered assistance via the Kapa widget. However, Mintlify is not loading the custom JavaScript despite following their documentation.

What it should do (once working):

  • When users type a search query, an "✨ Ask AI: [query]" option should appear as the first result
  • Clicking it closes the search modal and opens the Kapa AI widget with the query pre-filled and auto-submitted
  • Integrates with Statsig for user tracking when available

Current status:

❌ Script does not load in preview deployment (https://statsig-4b2ff144-devin-1760982871-add-search-ask-ai.mintlify.app)
❌ Functionality cannot be verified
❌ Three duplicate copies of the script exist from trying different loading methods

Issues to resolve before merging

  1. Script not loading: Tried three approaches per Mintlify docs, none work:

    • search-ask-ai.js in root directory (Mintlify docs say .js files auto-load)
    • snippets/head.html with inline script (Mintlify docs mention snippet support)
    • scripts/search-ask-ai.js with various reference attempts
  2. Need to investigate: Why isn't Mintlify loading custom scripts? May need:

    • Platform configuration/permissions
    • Different file structure
    • Contact Mintlify support
  3. Cleanup needed: Remove duplicate script files once we determine which approach works

Review checklist

  • CRITICAL: Verify why Mintlify isn't loading custom scripts (check docs/support)
  • Test if it works in production deployment (not just preview)
  • Verify Statsig client key on line 198 is correct: client-Wql5Tkj3Wa3sE8VpFjWpCHCPHxYZMbq6RfcRZZVHFdm
  • Once script loads, test complete flow: search → type query → click CTA → Kapa opens → auto-submit
  • Remove duplicate script files and keep only working approach
  • Verify DOM selectors work with current Mintlify version

Best practice checklist

  • I've considered the best practices on where to put your doc and what to put in your doc - N/A (JavaScript file, not documentation)
  • I've deleted and redirected old pages to this one, if any - N/A
  • I've updated links affected by this change, if any - N/A
  • I've updated screenshots affected by this change, if any - N/A

Questions?

Reach out to Brock, Tore, or Logan on Slack!


Link to Devin run: https://app.devin.ai/sessions/941173155f45427689d1f6d420d345bb
Requested by: [email protected] (@xhuang-statsig)

This script augments the Mintlify search bar with an Ask AI call-to-action
as the first search result. When users search for content, they'll see an
option to 'Ask AI' about their query, which seamlessly transitions them to
the Kapa AI widget to get instant AI-powered answers.

Features:
- Monitors Mintlify search modal for query input
- Injects a visually consistent 'Ask AI' CTA as the first search result
- Passes the search query to Kapa AI widget when clicked
- Auto-submits the query to start the AI conversation
- Integrates with Statsig for user tracking when available

This provides users with a smooth transition from search to AI assistance
while maintaining the native Mintlify search experience.
@devin-ai-integration
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

Updated script to properly detect and inject Ask AI CTA in production:
- Remove references to non-existent [cmdk-root] and [cmdk-list] attributes
- Use [aria-modal="true"] and [role="listbox"] selectors instead
- Simplify search dialog detection logic
- Update close button selector to handle case variations

The script now correctly finds the Mintlify search modal and listbox
container in production deployments.
Added continuous polling via requestAnimationFrame to reliably detect
search input changes. This ensures the Ask AI CTA is injected even if
the input event listener doesn't fire properly.

Changes:
- Added checkInput() function that polls for input value changes
- Keep input event listener as immediate trigger
- Use MutationObserver to detect when search dialog is removed
- Automatically clean up monitoring when dialog closes

This hybrid approach (polling + events) is more reliable than relying
solely on mutation observers or event listeners.
Created head.html snippet file to properly load the search-ask-ai.js script
via Mintlify's snippet injection mechanism. This ensures the script is loaded
on all pages and can properly augment the search functionality.
Added /scripts/search-ask-ai.js to the scripts array in docs.json to ensure
it gets loaded by Mintlify. This is the proper way to load custom scripts
in Mintlify deployments.
Instead of loading the script from /scripts/, inline the entire JavaScript
directly into the snippets/head.html file. This ensures Mintlify properly
loads the script since it may not serve files from the /scripts/ directory.

Also removed the scripts property from docs.json since it's not needed.
According to Mintlify documentation, any .js file in the content directory
(root) will be automatically included in every documentation page. Moved
the script from /scripts/ to the root directory to enable this feature.
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