Spaces:
Sleeping
Sleeping
lmbarak01 commited on
Commit ·
ad8d20e
1
Parent(s): 2477b7f
Surface ChatKit domain verification failure
Browse files- static/app.js +45 -5
static/app.js
CHANGED
|
@@ -211,6 +211,47 @@ let activeScenario = scenarios[0];
|
|
| 211 |
let activeJailbreakPrompt = jailbreakPrompts[0];
|
| 212 |
let activePatientDataPrompt = patientDataCompletePrompts[0];
|
| 213 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 214 |
function maybeShowEmbedWarning() {
|
| 215 |
// On Hugging Face, /spaces/... wraps the app in an iframe.
|
| 216 |
// Some embedded widgets work better from the direct *.hf.space URL.
|
|
@@ -220,7 +261,7 @@ function maybeShowEmbedWarning() {
|
|
| 220 |
if (!inIframe || host.endsWith(".hf.space")) return;
|
| 221 |
|
| 222 |
const directUrl = "https://pharma-ia-mit-summer-2026.hf.space";
|
| 223 |
-
embedWarning.innerHTML = `If chat appears blank here, open the direct Space URL: <a href="${directUrl}" target="_blank" rel="noopener noreferrer">${directUrl}</a>`;
|
| 224 |
embedWarning.style.display = "block";
|
| 225 |
embedWarning.style.color = "#7a271a";
|
| 226 |
}
|
|
@@ -414,11 +455,9 @@ async function initChatKit() {
|
|
| 414 |
},
|
| 415 |
});
|
| 416 |
|
| 417 |
-
|
| 418 |
-
chatStatus.style.color = "#4d5b64";
|
| 419 |
} catch (error) {
|
| 420 |
-
|
| 421 |
-
chatStatus.style.color = "#b42318";
|
| 422 |
}
|
| 423 |
}
|
| 424 |
|
|
@@ -460,6 +499,7 @@ renderScenarioButtons();
|
|
| 460 |
setScenario(activeScenario.id);
|
| 461 |
setJailbreakPrompt(activeJailbreakPrompt);
|
| 462 |
setPatientDataPrompt(activePatientDataPrompt);
|
|
|
|
| 463 |
maybeShowEmbedWarning();
|
| 464 |
prefillButton?.addEventListener("click", prefillPrompt);
|
| 465 |
prefillJailbreakButton?.addEventListener("click", () =>
|
|
|
|
| 211 |
let activeJailbreakPrompt = jailbreakPrompts[0];
|
| 212 |
let activePatientDataPrompt = patientDataCompletePrompts[0];
|
| 213 |
|
| 214 |
+
function setChatError(message) {
|
| 215 |
+
if (!chatStatus) return;
|
| 216 |
+
chatStatus.textContent = message;
|
| 217 |
+
chatStatus.style.color = "#b42318";
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
function setChatInfo(message) {
|
| 221 |
+
if (!chatStatus) return;
|
| 222 |
+
chatStatus.textContent = message;
|
| 223 |
+
chatStatus.style.color = "#4d5b64";
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
function formatChatKitError(error) {
|
| 227 |
+
const message =
|
| 228 |
+
typeof error === "string"
|
| 229 |
+
? error
|
| 230 |
+
: error?.message || error?.reason?.message || "Unknown ChatKit error";
|
| 231 |
+
|
| 232 |
+
if (message.includes("Domain verification failed")) {
|
| 233 |
+
return [
|
| 234 |
+
"ChatKit domain verification failed.",
|
| 235 |
+
"Add https://pharma-ia-mit-summer-2026.hf.space to the OpenAI domain allowlist, then reload this Space.",
|
| 236 |
+
].join(" ");
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
return `ChatKit error: ${message}`;
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
function installChatKitErrorHandlers() {
|
| 243 |
+
window.addEventListener("unhandledrejection", (event) => {
|
| 244 |
+
setChatError(formatChatKitError(event.reason));
|
| 245 |
+
});
|
| 246 |
+
|
| 247 |
+
window.addEventListener("error", (event) => {
|
| 248 |
+
const message = event.message || event.error?.message || "";
|
| 249 |
+
if (message.includes("ChatKit") || message.includes("Domain verification failed")) {
|
| 250 |
+
setChatError(formatChatKitError(event.error || message));
|
| 251 |
+
}
|
| 252 |
+
});
|
| 253 |
+
}
|
| 254 |
+
|
| 255 |
function maybeShowEmbedWarning() {
|
| 256 |
// On Hugging Face, /spaces/... wraps the app in an iframe.
|
| 257 |
// Some embedded widgets work better from the direct *.hf.space URL.
|
|
|
|
| 261 |
if (!inIframe || host.endsWith(".hf.space")) return;
|
| 262 |
|
| 263 |
const directUrl = "https://pharma-ia-mit-summer-2026.hf.space";
|
| 264 |
+
embedWarning.innerHTML = `If chat appears blank here, open the direct Space URL: <a href="${directUrl}" target="_blank" rel="noopener noreferrer">${directUrl}</a>. ChatKit also requires this exact domain in the OpenAI domain allowlist.`;
|
| 265 |
embedWarning.style.display = "block";
|
| 266 |
embedWarning.style.color = "#7a271a";
|
| 267 |
}
|
|
|
|
| 455 |
},
|
| 456 |
});
|
| 457 |
|
| 458 |
+
setChatInfo("ChatKit is connecting. Select a scenario once the input appears.");
|
|
|
|
| 459 |
} catch (error) {
|
| 460 |
+
setChatError(formatChatKitError(error));
|
|
|
|
| 461 |
}
|
| 462 |
}
|
| 463 |
|
|
|
|
| 499 |
setScenario(activeScenario.id);
|
| 500 |
setJailbreakPrompt(activeJailbreakPrompt);
|
| 501 |
setPatientDataPrompt(activePatientDataPrompt);
|
| 502 |
+
installChatKitErrorHandlers();
|
| 503 |
maybeShowEmbedWarning();
|
| 504 |
prefillButton?.addEventListener("click", prefillPrompt);
|
| 505 |
prefillJailbreakButton?.addEventListener("click", () =>
|