Skip to content

Commit 3f92d36

Browse files
authored
Merge pull request #29 from mongodb-developer/Agent_Assistant
Pavel's agent5ive assitant
2 parents 92baae3 + f2e223d commit 3f92d36

File tree

2 files changed

+73
-4
lines changed

2 files changed

+73
-4
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/theme/Layout/index.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import React, {useEffect} from "react";
2+
import Layout from "@theme-original/Layout";
3+
4+
const AGENT_SCRIPT_ID = "agent5ive-script";
5+
6+
const initAgent = () => {
7+
if (typeof window === "undefined") {
8+
return;
9+
}
10+
11+
if (window.__agent5iveInitialized) {
12+
return;
13+
}
14+
15+
if (window.AgentXChat?.init) {
16+
window.AgentXChat.init({
17+
deploymentId: "6926e113027b3de03c2f4f19",
18+
agentName: "MongoDB Security Basics",
19+
baseUrl: "https://www.agent5ive.com",
20+
buttonText: "Chat with MongoDB Security Basics",
21+
widgetThemeUrl:
22+
"https://pgysmrif8xfchszs.public.blob.vercel-storage.com/css/deployments/6926e113027b3de03c2f4f19/agent5ive-widget-theme-6926e113027b3de03c2f4f19.css",
23+
chatThemeUrl:
24+
"https://pgysmrif8xfchszs.public.blob.vercel-storage.com/css/deployments/6926e113027b3de03c2f4f19/agent5ive-chat-theme-6926e113027b3de03c2f4f19.css",
25+
});
26+
window.__agent5iveInitialized = true;
27+
} else {
28+
console.error("AgentXChat script failed to load.");
29+
}
30+
};
31+
32+
const loadAgentScript = () => {
33+
if (typeof document === "undefined") {
34+
return;
35+
}
36+
37+
if (document.getElementById(AGENT_SCRIPT_ID)) {
38+
initAgent();
39+
return;
40+
}
41+
42+
const script = document.createElement("script");
43+
script.id = AGENT_SCRIPT_ID;
44+
script.src = "https://www.agent5ive.com/agent5ive.js";
45+
script.defer = true;
46+
script.onload = initAgent;
47+
script.onerror = () => console.error("AgentXChat script failed to load.");
48+
49+
document.body.appendChild(script);
50+
};
51+
52+
export default function LayoutWrapper(props) {
53+
useEffect(() => {
54+
if (typeof window === "undefined") {
55+
return undefined;
56+
}
57+
58+
const handleLoad = () => initAgent();
59+
60+
loadAgentScript();
61+
window.addEventListener("load", handleLoad);
62+
63+
return () => {
64+
window.removeEventListener("load", handleLoad);
65+
};
66+
}, []);
67+
68+
return <Layout {...props} />;
69+
}

0 commit comments

Comments
 (0)