Skip to content
Merged
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
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 69 additions & 0 deletions src/theme/Layout/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import React, {useEffect} from "react";
import Layout from "@theme-original/Layout";

const AGENT_SCRIPT_ID = "agent5ive-script";

const initAgent = () => {
if (typeof window === "undefined") {
return;
}

if (window.__agent5iveInitialized) {
return;
}

if (window.AgentXChat?.init) {
window.AgentXChat.init({
deploymentId: "6926e113027b3de03c2f4f19",
agentName: "MongoDB Security Basics",
baseUrl: "https://www.agent5ive.com",
buttonText: "Chat with MongoDB Security Basics",
widgetThemeUrl:
"https://pgysmrif8xfchszs.public.blob.vercel-storage.com/css/deployments/6926e113027b3de03c2f4f19/agent5ive-widget-theme-6926e113027b3de03c2f4f19.css",
chatThemeUrl:
"https://pgysmrif8xfchszs.public.blob.vercel-storage.com/css/deployments/6926e113027b3de03c2f4f19/agent5ive-chat-theme-6926e113027b3de03c2f4f19.css",
});
window.__agent5iveInitialized = true;
} else {
console.error("AgentXChat script failed to load.");
}
};

const loadAgentScript = () => {
if (typeof document === "undefined") {
return;
}

if (document.getElementById(AGENT_SCRIPT_ID)) {
initAgent();
return;
}

const script = document.createElement("script");
script.id = AGENT_SCRIPT_ID;
script.src = "https://www.agent5ive.com/agent5ive.js";
script.defer = true;
script.onload = initAgent;
script.onerror = () => console.error("AgentXChat script failed to load.");

document.body.appendChild(script);
};

export default function LayoutWrapper(props) {
useEffect(() => {
if (typeof window === "undefined") {
return undefined;
}

const handleLoad = () => initAgent();

loadAgentScript();
window.addEventListener("load", handleLoad);

return () => {
window.removeEventListener("load", handleLoad);
};
}, []);

return <Layout {...props} />;
}