iscc-sct / docs /javascripts /copilot.js
titusz's picture
Sync to v0.2.2 (github.com/iscc/iscc-sct @ bf39b3a)
8ef3a6b verified
Raw History Blame Contribute Delete
889 Bytes
/**
* Mount the ISCC-AI copilot chat widget with anonymous authentication.
*
* Shared across all ISCC documentation sites. Do not modify per project.
*
* Fetches a JWT token from the copilot-token endpoint, then mounts the
* Chainlit copilot widget with the token for cross-origin authentication.
*/
window.addEventListener("load", async function () {
if (typeof window.mountChainlitWidget !== "function") return;
var server = "https://iscc.ai";
var tokenUrl = server + "/api/copilot-token";
try {
var response = await fetch(tokenUrl);
var data = await response.json();
window.mountChainlitWidget({
chainlitServer: server,
theme: "light",
accessToken: data.accessToken,
customCssUrl: window.location.origin + "/stylesheets/copilot.css?v=7",
});
} catch (e) {
console.warn("ISCC-AI copilot: failed to fetch token", e);
}
});