-
Notifications
You must be signed in to change notification settings - Fork 388
Expand file tree
/
Copy pathassistant.js
More file actions
32 lines (30 loc) · 1.55 KB
/
Copy pathassistant.js
File metadata and controls
32 lines (30 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Loads the docs AI assistant widget (celo-org/docs#2250).
//
// Mintlify includes every .js file in the content directory on all pages and
// does not support a raw <script src> tag in MDX, so the widget is injected
// programmatically. See AGENTS.md §1 for that mechanism.
(function () {
var WIDGET_SRC = 'https://docs-assistant.celo.org/widget.js';
// The assistant API only accepts these origins. Injecting anywhere else
// renders a button that collects a question and then fails CORS, so limit
// the widget to hosts where it actually works — production plus local
// `mint dev`, which AGENTS.md asks contributors to run before a PR.
var HOSTS = ['docs.celo.org', 'localhost', '127.0.0.1'];
if (HOSTS.indexOf(location.hostname) === -1) return;
var script = document.createElement('script');
script.src = WIDGET_SRC;
// The widget host answers with `access-control-allow-origin: *`, so a CORS
// load works. It is also what a future `integrity` attribute would require.
script.crossOrigin = 'anonymous';
// The widget reads this rather than inferring its own origin.
script.dataset.apiUrl = 'https://docs-assistant.celo.org/api/chat';
script.referrerPolicy = 'strict-origin';
script.onerror = function () {
// An ad blocker, an outage, or a blocked request otherwise leaves no
// button and no explanation for a reader told one would be there.
console.warn(
'[celo-docs] The AI assistant failed to load. It may be blocked by an extension or temporarily unavailable.'
);
};
document.head.appendChild(script);
})();