( sessionApiKey, authRequired, runtimeServicesInfo, lockToCloud, basePath, vscodeBasePath, disableTelemetry, )
| 376 | } |
| 377 | |
| 378 | function makeConfigInjectionScript( |
| 379 | sessionApiKey, |
| 380 | authRequired, |
| 381 | runtimeServicesInfo, |
| 382 | lockToCloud, |
| 383 | basePath, |
| 384 | vscodeBasePath, |
| 385 | disableTelemetry, |
| 386 | ) { |
| 387 | const parts = []; |
| 388 | |
| 389 | if (sessionApiKey) { |
| 390 | const keyLiteral = serializeForInlineScript(sessionApiKey); |
| 391 | // Window global — read at module init by getBakedSessionApiKey(). |
| 392 | // Set first so it's available even if the localStorage write throws. |
| 393 | parts.push(`window.__AGENT_CANVAS_SESSION_API_KEY__=${keyLiteral};`); |
| 394 | // Always overwrite when the stored key differs from the runtime key. |
| 395 | // A previous session may have persisted a now-stale key; the runtime |
| 396 | // value (from --session-api-key) is the server's truth. |
| 397 | parts.push( |
| 398 | `try{` + |
| 399 | `var _k='openhands-agent-server-config',` + |
| 400 | `_c=JSON.parse(localStorage.getItem(_k)||'{}');` + |
| 401 | `if(_c.sessionApiKey!==${keyLiteral}){` + |
| 402 | `_c.sessionApiKey=${keyLiteral};` + |
| 403 | `localStorage.setItem(_k,JSON.stringify(_c));` + |
| 404 | `}` + |
| 405 | `}catch(e){}`, |
| 406 | ); |
| 407 | } |
| 408 | |
| 409 | if (authRequired) { |
| 410 | parts.push(`window.__AGENT_CANVAS_AUTH_REQUIRED__=true;`); |
| 411 | } |
| 412 | |
| 413 | if (runtimeServicesInfo) { |
| 414 | // Stored as the raw JSON string so the browser-side parser |
| 415 | // (parseRuntimeServicesInfo) can JSON.parse it exactly like the |
| 416 | // VITE_RUNTIME_SERVICES_INFO env var. JSON.stringify produces a safe JS |
| 417 | // string literal for the inline <script>. |
| 418 | parts.push( |
| 419 | `window.__AGENT_CANVAS_RUNTIME_SERVICES_INFO__=${serializeForInlineScript(runtimeServicesInfo)};`, |
| 420 | ); |
| 421 | } |
| 422 | |
| 423 | if (lockToCloud) { |
| 424 | parts.push( |
| 425 | `window.__AGENT_CANVAS_LOCK_TO_CLOUD__=${serializeForInlineScript(lockToCloud)};`, |
| 426 | ); |
| 427 | } |
| 428 | |
| 429 | if (basePath && basePath !== "/") { |
| 430 | parts.push( |
| 431 | `window.__AGENT_CANVAS_BASE_PATH__=${serializeForInlineScript(basePath)};`, |
| 432 | ); |
| 433 | } |
| 434 | |
| 435 | if (vscodeBasePath) { |
no test coverage detected