Harden skip-agent network logic and remove HelloSkip strings
cgen-e2cdb0fca2e44d0a907845424feb493a
This commit is contained in:
parent
bbc825032a
commit
3d47081be1
1 changed files with 21 additions and 4 deletions
|
|
@ -223,8 +223,25 @@ const isSkipAgentReachable = async (): Promise<boolean> => {
|
||||||
const timeout = window.setTimeout(() => controller.abort(), 4000);
|
const timeout = window.setTimeout(() => controller.abort(), 4000);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const agentSrc = getAgentSrc();
|
||||||
|
if (!agentSrc) {
|
||||||
|
window.clearTimeout(timeout);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
let origin: string;
|
||||||
|
try {
|
||||||
|
origin = new URL(agentSrc).origin;
|
||||||
|
} catch (e) {
|
||||||
|
window.clearTimeout(timeout);
|
||||||
|
if (shouldEnableSkipAgent) {
|
||||||
|
console.warn("Invalid agent src; skipping status check", agentSrc);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`${SKIP_AGENT_ORIGIN}/api/agent/status?agentId=${encodeURIComponent(SKIP_AGENT_ID)}`,
|
`${origin}/api/agent/status?agentId=${encodeURIComponent(getAgentId())}`,
|
||||||
{
|
{
|
||||||
method: "GET",
|
method: "GET",
|
||||||
mode: "cors",
|
mode: "cors",
|
||||||
|
|
@ -239,7 +256,7 @@ const isSkipAgentReachable = async (): Promise<boolean> => {
|
||||||
window.clearTimeout(timeout);
|
window.clearTimeout(timeout);
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(`Skip agent status request failed with ${response.status}`);
|
throw new Error(`Agent status request failed with ${response.status}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const payload = (await response.json().catch(() => null)) as
|
const payload = (await response.json().catch(() => null)) as
|
||||||
|
|
@ -247,7 +264,7 @@ const isSkipAgentReachable = async (): Promise<boolean> => {
|
||||||
| null;
|
| null;
|
||||||
|
|
||||||
if (payload && payload.active === false) {
|
if (payload && payload.active === false) {
|
||||||
throw new Error("Skip agent is inactive");
|
throw new Error("Agent reported inactive");
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -255,7 +272,7 @@ const isSkipAgentReachable = async (): Promise<boolean> => {
|
||||||
window.clearTimeout(timeout);
|
window.clearTimeout(timeout);
|
||||||
if (shouldEnableSkipAgent) {
|
if (shouldEnableSkipAgent) {
|
||||||
console.warn(
|
console.warn(
|
||||||
"Skip Agent status endpoint unreachable; skipping embed to prevent runtime errors:",
|
"Agent status endpoint unreachable; skipping embed to prevent runtime errors:",
|
||||||
error,
|
error,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue