Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Gurubase integration #716

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tough-pots-help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@gitbook/integration-gurubase': major
---

Add Gurubase (https://gurubase.io/) integration to Gitbook
14 changes: 14 additions & 0 deletions bun.lock
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,18 @@
"@gitbook/tsconfig": "packages/tsconfig",
},
},
"integrations/gurubase": {
"name": "@gitbook/integration-gurubase",
"version": "0.1.0",
"dependencies": {
"@gitbook/api": "*",
"@gitbook/runtime": "*",
},
"devDependencies": {
"@gitbook/cli": "workspace:*",
"@gitbook/tsconfig": "workspace:*",
},
},
"integrations/heap": {
"name": "@gitbook/integration-heap",
"version": "0.5.2",
Expand Down Expand Up @@ -863,6 +875,8 @@

"@gitbook/integration-googleanalytics": ["@gitbook/integration-googleanalytics@workspace:integrations/googleanalytics"],

"@gitbook/integration-gurubase": ["@gitbook/integration-gurubase@workspace:integrations/gurubase"],

"@gitbook/integration-heap": ["@gitbook/integration-heap@workspace:integrations/heap"],

"@gitbook/integration-helpscout": ["@gitbook/integration-helpscout@workspace:integrations/helpscout"],
Expand Down
5 changes: 5 additions & 0 deletions integrations/gurubase/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# @gitbook/integration-gurubase

## 0.1.0

Initial release of the Gurubase integration.
14 changes: 14 additions & 0 deletions integrations/gurubase/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Gurubase

```bash
curl -fsSL https://bun.sh/install | bash

cd packages/api
bun run build

cd ../../integrations/gurubase
bun install
gitbook publish
cd ../../
bun changeset
```
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added integrations/gurubase/assets/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
107 changes: 107 additions & 0 deletions integrations/gurubase/gitbook-manifest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: gurubase
title: Gurubase
icon: ./assets/icon.png
previewImages:
- ./assets/gurubase-preview.png
description: Add the Gurubase widget to your published GitBook content.
externalLinks:
- label: Website
url: https://gurubase.io/
visibility: public
script: ./src/index.ts
# The following scope(s) are available only to GitBook Staff
# See https://developer.gitbook.com/integrations/configurations#scopes
scopes:
- site:script:inject
organization: hY1Io78AJIno02pEZkOX
contentSecurityPolicy:
font-src: |
*.gurubase.io;
script-src: |
*.gurubase.io;
style-src: |
'self'
'unsafe-inline'
fonts.googleapis.com
*.gurubase.io
unpkg.com
cdnjs.cloudflare.com;
frame-src: |
*.gurubase.io;
child-src: |
*.gurubase.io;
img-src: |
*.gurubase.io;
connect-src: |
*.gurubase.io;
media-src: |
*.gurubase.io;
summary: |
# Overview
Add an AI-powered chat widget to your GitBook documentation using Gurubase. This integration enables real-time AI assistance for your readers directly within your documentation pages.

## Prerequisites
- You need to have a Guru created on Gurubase.io
- You need a Widget ID from your Guru's settings page
1. Go to "My Gurus" page
2. Select your Guru
3. Click "Integrations" then "Web Widget"
4. Create a new widget and copy the Widget ID

## Features
- Seamless integration with GitBook pages
- Customizable widget appearance
- Light/Dark mode support
- Custom positioning
- Custom branding options

# Configuration
1. Install the integration on your GitBook site
2. Add your Widget ID from Gurubase dashboard
3. Customize the widget appearance (optional)

categories:
- support
configurations:
site:
properties:
widgetId:
type: string
title: Gurubase Widget ID
description: "Available in your Guru's settings page under Integrations > Web Widget"
text:
type: string
title: Text (Optional)
description: "Text to display in the widget button. (default: 'Ask AI')"
bottomMargin:
type: string
title: Bottom Margin (Optional)
description: 'Bottom margin of the widget. Examples: 20px, 1rem. (default: 20px)'
rightMargin:
type: string
title: Right Margin (Optional)
description: 'Right margin of the widget. Examples: 20px, 1rem. (default: 20px)'
lightMode:
type: boolean
title: Light Mode
description: Whether to use light mode
bgColor:
type: string
title: Main Color (Optional)
description: "Main color of the widget. Examples: #000000, #ffffff. (default: Guru's main color)"
iconUrl:
type: string
title: Icon URL (Optional)
description: "URL of the icon to display in the widget. (default: Guru's avatar)"
name:
type: string
title: Name (Optional)
description: "Name of the widget. (default: Guru's name)"
baseUrl:
type: string
title: Base Backend URL (Optional)
description: 'Base URL for Gurubase backend. (default: https://api.gurubase.io)'

required:
- widgetId
target: site
19 changes: 19 additions & 0 deletions integrations/gurubase/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "@gitbook/integration-gurubase",
"version": "0.1.0",
"private": true,
"dependencies": {
"@gitbook/api": "*",
"@gitbook/runtime": "*"
},
"devDependencies": {
"@gitbook/cli": "workspace:*",
"@gitbook/tsconfig": "workspace:*"
},
"scripts": {
"typecheck": "tsc --noEmit",
"publish-integrations-staging": "gitbook publish .",
"check": "gitbook check",
"publish-integrations": "gitbook publish ."
}
}
69 changes: 69 additions & 0 deletions integrations/gurubase/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import {
createIntegration,
FetchPublishScriptEventCallback,
RuntimeContext,
RuntimeEnvironment,
} from '@gitbook/runtime';

import script from './script.raw.js';

type GurubaseRuntimeContext = RuntimeContext<
RuntimeEnvironment<
{},
{
widgetId?: string;
text?: string;
bottomMargin?: string;
rightMargin?: string;
lightMode?: boolean;
bgColor?: string;
iconUrl?: string;
name?: string;
baseUrl?: string;
}
>
>;

export const handleFetchEvent: FetchPublishScriptEventCallback = async (
event,
{ environment }: GurubaseRuntimeContext,
) => {
const config = environment.siteInstallation?.configuration || {};
const widgetId = config.widgetId;

if (!widgetId) {
throw new Error(
`The Gurubase Widget ID is missing from the configuration (ID: ${
'spaceId' in event ? event.spaceId : event.siteId
}).`,
);
}

const scriptConfig = {
widgetId,
text: config.text,
margins: JSON.stringify({
bottom: config.bottomMargin || '20px',
right: config.rightMargin || '20px',
}),
lightMode: config.lightMode,
bgColor: config.bgColor,
iconUrl: config.iconUrl,
name: config.name,
baseUrl: config.baseUrl,
};

// Properly escape the config JSON for safe insertion into JavaScript
const escapedConfig = JSON.stringify(scriptConfig).replace(/'/g, "\\'").replace(/"/g, '\\"');

return new Response((script as string).replace("'<TO_REPLACE>'", `'${escapedConfig}'`), {
headers: {
'Content-Type': 'application/javascript',
'Cache-Control': 'max-age=604800',
},
});
};

export default createIntegration<GurubaseRuntimeContext>({
fetch_published_script: handleFetchEvent,
});
38 changes: 38 additions & 0 deletions integrations/gurubase/src/script.raw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
(function (d, s) {
const config = JSON.parse('<TO_REPLACE>');
const widgetId = config.widgetId;

window.$gurubase = [];
window.GURUBASE_WIDGET_ID = widgetId;

d = document;
s = d.createElement('script');
s.src = 'https://widget.gurubase.io/widget.latest.min.js';
s.async = 1;
s.setAttribute('data-widget-id', widgetId);

if (config.text) {
s.setAttribute('data-text', config.text);
}
if (config.margins) {
s.setAttribute('data-margins', config.margins);
}
if (config.lightMode !== undefined) {
s.setAttribute('data-light-mode', config.lightMode.toString());
}
if (config.bgColor) {
s.setAttribute('data-bg-color', config.bgColor);
}
if (config.iconUrl) {
s.setAttribute('data-icon-url', config.iconUrl);
}
if (config.name) {
s.setAttribute('data-name', config.name);
}
if (config.baseUrl) {
s.setAttribute('data-baseUrl', config.baseUrl);
}

s.id = 'guru-widget-id';
d.getElementsByTagName('head')[0].appendChild(s);
})(window, document);
3 changes: 3 additions & 0 deletions integrations/gurubase/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "@gitbook/tsconfig/integration.json"
}