Skip to content

Adding Kapa AI script tag#2727

Merged
zaerl merged 5 commits intotrunkfrom
adding-kapa-ai-to-docs
Oct 9, 2025
Merged

Adding Kapa AI script tag#2727
zaerl merged 5 commits intotrunkfrom
adding-kapa-ai-to-docs

Conversation

@fellyph
Copy link
Collaborator

@fellyph fellyph commented Oct 7, 2025

This pull request adds a new AI assistant widget to the WordPress Playground documentation site by updating the Docusaurus configuration. The widget is integrated via a script and includes custom branding, bot protection, and messaging.

Integration of the AI assistant widget:

  • Added a new entry to the scripts array in docusaurus.config.js to load the Kapa AI widget, including configuration options for project branding, modal titles, and example questions.
  • Added the Kapa script to a custom plugin to make it possible to load the current locale
  • Map Playground locales to Kapa locales
  • Added i18n
  • Translated in ES
immagine immagine

How to test it?

  • From top folder, run the command npm run build:docs, then npm run dev:docs
  • Check the button on top right

Switching to different locales by using the locale dropdown is not possible on localhost. To test another locale, do this:

cd packages/docs/site
npm run start -- --locale es # es, for example

And be sure the Kapa UI is in Spanish:
immagine

@fellyph fellyph requested review from akirk and zaerl October 7, 2025 06:58
@fellyph fellyph added the [Type] Documentation Improvements or additions to documentation label Oct 7, 2025
@akirk
Copy link
Member

akirk commented Oct 7, 2025

Is there a way to preview this?

@fellyph
Copy link
Collaborator Author

fellyph commented Oct 7, 2025

I have included the script to test it

@zaerl
Copy link
Collaborator

zaerl commented Oct 7, 2025

Is there a way to preview this?

Not online, AFAIK. Offline by running npm run dev:docs is enough. It is working despite the website-id.

@akirk akirk changed the title Adding Papa AI script tag Adding Kapa AI script tag Oct 7, 2025
@akirk
Copy link
Member

akirk commented Oct 7, 2025

I run into this error:

Module not found: Error: Can't resolve './model.json' in 'packages/docs/site/src'
client (webpack 5.99.5) compiled with 1 error

I'd like to suggest to replace the search box instead of adding another button.

@zaerl
Copy link
Collaborator

zaerl commented Oct 7, 2025

I'd like to suggest to replace the search box instead of adding another button.

This is a good idea. The UI is a bit too crowded with that new button.

@adamziel
Copy link
Collaborator

adamziel commented Oct 7, 2025

I'd like to suggest to replace the search box instead of adding another button.

I'm not convinced about removing the search box – isn't that what people habitually look for?

@zaerl
Copy link
Collaborator

zaerl commented Oct 7, 2025

I'm not convinced about removing the search box – isn't that what people habitually look for?

It is possible to integrate Kapa in the search bar, without removing it. So we can bundle the two things together.

@zaerl
Copy link
Collaborator

zaerl commented Oct 7, 2025

Can't resolve './model.json'

Run npx nx build docs-site; it will resolve this issue.

@zaerl
Copy link
Collaborator

zaerl commented Oct 8, 2025

By making some experiments, I've seen that we can indeed "swizzle" the Algolia default SearchBar component by running

npm run swizzle @docusaurus/theme-search-algolia SearchBar

This, however, can bring us to two results:

By ejecting it, we will have the entire React component recreated in the directory. It's an unsafe operation, because the component can change in the future. Additionally, it doesn't allow you to modify the internal DocSearchModal component where the button is inserted in the example. Docusaurus does not use react-instantsearch directly (i.e., the <InstantSearch /> component).

By not ejecting it, Docusaurus creates a wrapper around <SearchBar {...props} /> which is not touched. In this mode, we can try to inject that button at runtime. But it's not a very elegant solution.

I will check if the <SearchBar /> can help us customize the results without adding or replacing too much code, and be sure future updates don't break it. The button will just need to open the Kapa model with the searched query, and nothing more.

@akirk
Copy link
Member

akirk commented Oct 8, 2025

Thanks for the assessment! I thought it might be much easier. Is it possible to just put the "Ask AI" button from @fellyph's screenshot to the top right next to the search bar? I think the thing that mostly disliked about the proposed solution is that we spread out the action points from left and top now also to bottom right.

@zaerl
Copy link
Collaborator

zaerl commented Oct 8, 2025

We can add this here, possibly attracting the user's attention until they don't use it. By hiding the other button.

Registrazione.schermo.2025-10-08.alle.17.59.17.mov

@fellyph
Copy link
Collaborator Author

fellyph commented Oct 8, 2025

We can add to the homepage a message about the new Ask AI button

@adamziel
Copy link
Collaborator

adamziel commented Oct 8, 2025

I like the top bar button!

@zaerl zaerl force-pushed the adding-kapa-ai-to-docs branch from 6fe19bb to e341f88 Compare October 9, 2025 09:00
@zaerl zaerl self-assigned this Oct 9, 2025
@akirk
Copy link
Member

akirk commented Oct 9, 2025

This is great. Is it easy to make it a button and move it to the right edge?

@zaerl
Copy link
Collaborator

zaerl commented Oct 9, 2025

I've added i18n, so it is localizable. The Spanish localization is already ok.

@zaerl
Copy link
Collaborator

zaerl commented Oct 9, 2025

This is great. Is it easy to make it a button and move it to the right edge?

We can swizzle the headbar because <SearchBar>, dark mode, and locales are hardcoded on the right. Let me try.

@zaerl
Copy link
Collaborator

zaerl commented Oct 9, 2025

@akirk, it was easier than I thought. No need to swizzle the entire headbar, but the search element. We can have a blue-style button on the right.

Registrazione.schermo.2025-10-09.alle.12.57.39.mov

@zaerl zaerl removed their request for review October 9, 2025 11:58
Copy link
Member

@akirk akirk left a comment

Choose a reason for hiding this comment

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

Nice! Let's ship it!

@zaerl zaerl merged commit a986d64 into trunk Oct 9, 2025
28 checks passed
@zaerl zaerl deleted the adding-kapa-ai-to-docs branch October 9, 2025 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants