Skip to content

Swizzle and use agentStudio for ask AI - #3052

Merged
shahbaz17 merged 1 commit into
mainfrom
ai-fixes
Sep 14, 2026
Merged

shahbaz17 merged 1 commit into
mainfrom
ai-fixes

Conversation

@yashovardhan

@yashovardhan yashovardhan commented Sep 7, 2026

Copy link
Copy Markdown
Member

Docusaurus doesn't by default support the agentStudio from Algolia. Using LiteLLM for us requires us to switch to agentStudio and use our custom integration. This PR swizzles out the component to make that parameter supported and working.


Note

Medium Risk
Ask AI changes add a global fetch patch and keyboard handling when an assistant ID is set; impact is limited to search/AI UX, not auth or data storage.

Overview
This PR wires Algolia DocSearch Ask AI to Agent Studio (needed for the LiteLLM-backed assistant) instead of relying on Docusaurus config alone, which cannot pass the agentStudio flag because Joi validation rejects unknown keys.

Configuration: The hardcoded askAi.assistantId is removed; ALGOLIA_ASSISTANT_ID from the environment optionally enables themeConfig.algolia.askAi. A swizzled SearchBar merges agentStudio: true into Ask AI props at runtime, and Root passes the same flag to DocSearchSidepanel and mounts the sidepanel only when an assistant ID is present.

Runtime fixes: New installAskAiWorkarounds() patches Agent Studio–specific DocSearch v4 issues: an Enter-key guard so Ask AI submits the query the user typed (not a stale highlighted option), and a scoped fetch interceptor that blocks spurious auto-resubmits that Agent Studio rejects with 422.

Tooling: globals.d.ts adds a Docusaurus type reference so the tsc-files pre-commit hook type-checks staged theme files reliably.

Reviewed by Cursor Bugbot for commit 929562b. Bugbot is set up for automated code reviews on this repo. Configure here.

@yashovardhan
yashovardhan requested review from a team as code owners September 7, 2026 13:55
@vercel

vercel Bot commented Sep 7, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated
metamask-docs Ready Ready Preview Sep 8, 2026 11:29pm UTC

Request Review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread docusaurus.config.js Outdated
shahbaz17 added a commit that referenced this pull request Sep 8, 2026
Code blocks in Ask AI answers rendered as unstyled, low-contrast text: the
copy button overlapped the first line and long lines wrapped mid-URL.

DocSearch renders fenced blocks through its own marked renderer as:

  <div class="DocSearch-CodeSnippet">
    <button class="DocSearch-CodeSnippet-CopyButton">...</button>
    <pre><code class="language-tsx">...</code></pre>
  </div>

@docsearch/css ships no styling for that <pre>/<code> at all - only
`position: relative` on the wrapper plus the copy button chrome - so the
snippet inherited whatever the surrounding answer styles happened to set.

Snippets now match the site's own code blocks (theme/_prism-code.scss):
`--general-black-light` surface, `--inline-code-font`, `--general-gray` text,
horizontal scroll instead of wrapping, and top padding that clears the copy
button. Applied globally rather than scoped to a container so it covers both
the search modal and the Ask AI sidepanel.

Two things worth noting:

- The existing sidepanel rules force `code { color: #373739 !important }` in
  light mode, which is unreadable on the dark snippet surface. The snippet
  `code` colour is therefore set with matching specificity and !important,
  scoped under both sidepanel colour modes.
- DocSearch does not syntax highlight. The marked renderer only emits a
  `language-*` class, with no Prism/highlight.js pass, so this change covers
  contrast, typography and layout - not token colours.

Also folds in the DocSearch CSS from PR #3052 (branch `ai-fixes`), which
overlaps this branch: `.DocSearch-Button` margin/transition, and
`.DocSearch-Container` z-index to lift the modal above the fixed navbar. Kept
in _doc-search.scss rather than a separate src/theme/SearchBar/styles.css so
all DocSearch styling stays in one place.

Not copied from #3052: its `:root` `--docsearch-primary-color` /
`--docsearch-text-color` pair. This file already overrides both per colour
mode, and has those exact two lines commented out on purpose at the top;
re-adding them at `:root` would leak a purple primary to DocSearch surfaces
rendered outside `.DocSearch`. Its blanket `.DocSearch-Button-Key
{ padding: 0 }` is included but is largely inert, since
`.DocSearch-Button-Key:first-child` in custom.scss sets padding with
!important.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 929562b. Configure here.

Comment thread src/lib/algolia-ask-ai.ts
window.clearInterval(poll)
submit(input)
}
}, OPTION_CATCH_UP_POLL_MS)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Duplicate Ask AI submits on Enter

Medium Severity

Each intercepted Enter starts a new poll without canceling one already in flight, so a second Enter before the Ask AI option catches up replays submit more than once. Cleanup also leaves those intervals running, so a late replay can still fire after the listener is removed.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 929562b. Configure here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's fix this too @yashovardhan

@shahbaz17 shahbaz17 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

@shahbaz17
shahbaz17 merged commit d88783b into main Sep 14, 2026
19 checks passed
@shahbaz17
shahbaz17 deleted the ai-fixes branch September 14, 2026 07:47

This branch was successfully deployed

1 active deployment
Preview 929562b7 Deployed Sep 8, 2026 by vercel[bot]
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