Skip to content

feat(docs): add Kapa.ai widget for AI-powered documentation assistance - #11891

Merged
dlhck merged 4 commits into
masterfrom
kapa-ai-widgetz
Jan 5, 2026
Merged

dlhck merged 4 commits into
masterfrom
kapa-ai-widgetz

Conversation

@dlhck

@dlhck dlhck commented Jan 5, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add Kapa.ai chat widget to the documentation site
  • Widget provides AI-powered search and Q&A for documentation
  • Configured with TypeORM branding (color, logo, project name)
  • Only loads in production environment (consistent with existing Plausible analytics)

Test plan

  • Deploy to staging/preview environment
  • Verify the Kapa.ai widget appears on documentation pages
  • Test chat functionality responds correctly to TypeORM-related questions

Add the Kapa.ai chat widget to the documentation site to help users
find answers to their questions using AI-powered search.
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 Security concerns

Potential sensitive information exposure:
The data-website-id value '216c70e7-22e1-4425-bc7a-4af657c59eb2' is hardcoded in the configuration. If this is a private API key or secret token rather than a public identifier, it should be moved to environment variables and accessed via process.env.KAPA_WEBSITE_ID. Additionally, loading third-party JavaScript from an external domain (widget.kapa.ai) introduces supply chain risk. Consider implementing Content Security Policy (CSP) headers and Subresource Integrity (SRI) to mitigate potential XSS attacks if the external script is compromised.

⚡ Recommended focus areas for review

Sensitive ID Exposure

The data-website-id attribute contains what appears to be a unique identifier that is hardcoded in the configuration. Verify this is intended to be public and not a sensitive API key or secret that should be stored in environment variables.

"data-website-id": "216c70e7-22e1-4425-bc7a-4af657c59eb2",
"data-project-name": "TypeORM",
External Resource Trust

The widget loads JavaScript from an external domain (widget.kapa.ai) with async loading. Consider implementing Subresource Integrity (SRI) hashes to ensure the loaded script hasn't been tampered with, or verify that Kapa.ai provides security guarantees for their CDN.

    src: "https://widget.kapa.ai/kapa-widget.bundle.js",
    "data-website-id": "216c70e7-22e1-4425-bc7a-4af657c59eb2",
    "data-project-name": "TypeORM",
    "data-project-color": "#d94400",
    "data-project-logo":
        "https://typeorm.io/img/typeorm-icon-colored.png",
    async: true,
},

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jan 5, 2026 •

Copy link
Copy Markdown

Deploying typeorm with  Cloudflare Pages  Cloudflare Pages

Latest commit: f3c0d02
Status: ✅  Deploy successful!
Preview URL: https://39329367.typeorm.pages.dev
Branch Preview URL: https://kapa-ai-widgetz.typeorm.pages.dev

View logs

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Jan 5, 2026 •

Copy link
Copy Markdown

PR Code Suggestions ✨

Latest suggestions up to f3c0d02

CategorySuggestion                                                                                                                                    Impact
General
Increase z-index to prevent layering issues

Increase the navbar's z-index from 100 to a higher value like 1000 to prevent it
from being hidden behind the new Kapa.ai widget.

docs/src/css/custom.css [129]

-z-index: 100 !important;
+z-index: 1000 !important;
  • Apply / Chat
Suggestion importance[1-10]: 7

__

Why: This suggestion correctly identifies a potential UI bug where the navbar could be obscured by the newly added widget due to the z-index reduction. It's an important catch for site usability.

Medium
Add defer attribute for performance

Add the defer: true attribute to the Kapa.ai widget script to improve loading
performance and maintain consistency with other scripts.

docs/docusaurus.config.ts [44-52]

 {
     src: "https://widget.kapa.ai/kapa-widget.bundle.js",
     "data-website-id": "a9979852-2282-4862-87b3-b3631fb63d46",
     "data-project-name": "TypeORM",
     "data-project-color": "#d94400",
     "data-project-logo":
         "https://typeorm.io/img/typeorm-icon-colored.png",
     async: true,
+    defer: true,
 },
  • Apply / Chat
Suggestion importance[1-10]: 3

__

Why: The suggestion is valid for consistency, but the script already includes async: true, which also prevents render-blocking, making the addition of defer: true a minor improvement with low impact.

Low
  • More

Previous suggestions

Suggestions up to commit 5f13da3
CategorySuggestion                                                                                                                                    Impact
General
Verify navbar z-index hierarchy

Verify the navbar z-index is high enough to prevent it from being overlapped by
the new Kapa.ai widget. Consider increasing it from 1000 to a higher value like
9999.

docs/src/css/custom.css [129]

-z-index: 1000 !important;
+z-index: 9999 !important;
Suggestion importance[1-10]: 7

__

Why: This is a valid and important concern, as reducing the z-index of the navbar could cause it to be obscured by the new widget, impacting site usability. The suggestion correctly identifies a potential UI bug introduced by the PR's changes.

Medium
Add defer attribute for script loading

Add error handling for the Kapa.ai widget script to prevent issues if it fails
to load. For example, consider adding an onerror handler.

docs/docusaurus.config.ts [44-52]

 {
     src: "https://widget.kapa.ai/kapa-widget.bundle.js",
     "data-website-id": "a9979852-2282-4862-87b3-b3631fb63d46",
     "data-project-name": "TypeORM",
     "data-project-color": "#d94400",
     "data-project-logo":
         "https://typeorm.io/img/typeorm-icon-colored.png",
     async: true,
+    defer: true,
 },
Suggestion importance[1-10]: 2

__

Why: The suggestion content about error handling is valid, but the improved_code is unrelated as it adds defer: true, which is also technically questionable alongside the existing async: true.

Low
Suggestions up to commit 144951b
CategorySuggestion                                                                                                                                    Impact
General
Add defer attribute for performance

Add the defer attribute to the Kapa.ai widget script to prevent it from blocking
page rendering and improve load performance.

docs/docusaurus.config.ts [44-52]

 {
     src: "https://widget.kapa.ai/kapa-widget.bundle.js",
     "data-website-id": "a9979852-2282-4862-87b3-b3631fb63d46",
     "data-project-name": "TypeORM",
     "data-project-color": "#d94400",
     "data-project-logo":
         "https://typeorm.io/img/typeorm-icon-colored.png",
+    defer: true,
     async: true,
 },
Suggestion importance[1-10]: 6

__

Why: The suggestion correctly recommends adding the defer attribute for the new script, which is a best practice for performance as it prevents the script from blocking page rendering.

Low
Suggestions up to commit 7f65d0e
CategorySuggestion                                                                                                                                    Impact
Security
Add Subresource Integrity for security

Add Subresource Integrity (SRI) attributes (integrity and crossorigin) to the
third-party script configuration to enhance security.

docs/docusaurus.config.ts [44-52]

 {
     src: "https://widget.kapa.ai/kapa-widget.bundle.js",
     "data-website-id": "216c70e7-22e1-4425-bc7a-4af657c59eb2",
     "data-project-name": "TypeORM",
     "data-project-color": "#d94400",
     "data-project-logo":
         "https://typeorm.io/img/typeorm-icon-colored.png",
     async: true,
+    integrity: "sha384-...", // Replace with the generated hash
+    crossorigin: "anonymous",
 },
Suggestion importance[1-10]: 9

__

Why: The suggestion correctly points out a significant security improvement by adding Subresource Integrity (SRI) to a third-party script, which prevents loading a potentially compromised file.

High
General
Avoid hardcoding configuration values

Refactor the Kapa.ai script configuration to use existing config variables and
environment variables instead of hardcoded values for better maintainability.

docs/docusaurus.config.ts [46-50]

-"data-website-id": "216c70e7-22e1-4425-bc7a-4af657c59eb2",
-"data-project-name": "TypeORM",
-"data-project-logo":
-    "https://typeorm.io/img/typeorm-icon-colored.png",
+"data-website-id": process.env.KAPA_WEBSITE_ID,
+"data-project-name": config.title,
+"data-project-logo": `${config.url}/img/typeorm-icon-colored.png`,
Suggestion importance[1-10]: 6

__

Why: This is a good suggestion for improving maintainability by replacing hardcoded values with existing configuration variables (config.title, config.url) and an environment variable for the ID.

Low

@gioboa gioboa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

That's great 👏

@gioboa

gioboa commented Jan 5, 2026

Copy link
Copy Markdown
Collaborator

There is an overlay issue though
Screenshot 2026-01-05 at 10 51 26

@dlhck

dlhck commented Jan 5, 2026

Copy link
Copy Markdown
Collaborator Author

There is an overlay issue though
resolved

@dlhck
dlhck requested a review from naorpeled January 5, 2026 09:59
@dlhck
dlhck merged commit e3a445d into master Jan 5, 2026
@dlhck
dlhck deleted the kapa-ai-widgetz branch January 5, 2026 10:06
@alumni

alumni commented Jan 5, 2026

Copy link
Copy Markdown
Collaborator

@dlhck we've got a CORS error - the widget was added (only) to dev.typeorm.io, but the subdomain is not allowed.

@dlhck

dlhck commented Jan 5, 2026

Copy link
Copy Markdown
Collaborator Author

@alumni I've added a wildcard for the subdomains of typeorm.io now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

5 participants