From 1373b4746bc9ad8ea054c13900efa8e8ad5060a8 Mon Sep 17 00:00:00 2001 From: sir1st <1174702930@qq.com> Date: Thu, 28 May 2026 22:36:07 +0800 Subject: [PATCH] feat(version-check): add HERMES_WEB_UI_DISABLE_UPDATE_CHECK env var (#1105) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds an opt-in environment variable to suppress the npm-registry update check. When set, three things change: 1. checkLatestVersion() returns immediately (no outbound fetch) 2. startVersionCheck() does not arm the 30-minute interval 3. /api/health returns webui_latest='' and webui_update_available=false Use case: hermes-web-ui is bundled inside a packaged distribution like a desktop app where the user cannot `npm install -g hermes-web-ui@latest` to apply an upgrade. The 'update available' prompt is then misleading (the user would have to wait for the wrapper app to ship a new release), and the recurring HTTPS call to the npm registry is unnecessary noise. Set HERMES_WEB_UI_DISABLE_UPDATE_CHECK=true | 1 | on | yes to disable. The default behavior is unchanged. Discussed in #1091 — proposed by @EKKOLearnAI. --- packages/server/src/controllers/health.ts | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/server/src/controllers/health.ts b/packages/server/src/controllers/health.ts index 7a47249..62ce153 100644 --- a/packages/server/src/controllers/health.ts +++ b/packages/server/src/controllers/health.ts @@ -45,7 +45,23 @@ const LOCAL_VERSION = typeof __APP_VERSION__ !== 'undefined' let cachedLatestVersion = '' +/** + * Whether the periodic npm-registry version check is disabled. + * + * Useful when hermes-web-ui is bundled inside a packaged distribution + * (e.g. a desktop app) where the user can't `npm install -g hermes-web-ui@latest` + * to upgrade — the "update available" prompt would be misleading and + * the periodic outbound HTTP request to the npm registry is unnecessary. + * + * Set HERMES_WEB_UI_DISABLE_UPDATE_CHECK=true (or 1, on, yes) to disable. + */ +function isUpdateCheckDisabled(): boolean { + const raw = (process.env.HERMES_WEB_UI_DISABLE_UPDATE_CHECK || '').trim().toLowerCase() + return raw === 'true' || raw === '1' || raw === 'on' || raw === 'yes' +} + export async function checkLatestVersion(): Promise { + if (isUpdateCheckDisabled()) return try { const packageName = PACKAGE_INFO?.name || 'hermes-web-ui' const registryName = encodeURIComponent(packageName) @@ -61,6 +77,7 @@ export async function checkLatestVersion(): Promise { } export function startVersionCheck(): void { + if (isUpdateCheckDisabled()) return setTimeout(checkLatestVersion, 5000) setInterval(checkLatestVersion, 30 * 60 * 1000) } @@ -74,8 +91,10 @@ export async function healthCheck(ctx: any) { version: hermesVersion, gateway: 'running', webui_version: LOCAL_VERSION, - webui_latest: cachedLatestVersion, - webui_update_available: Boolean(LOCAL_VERSION && cachedLatestVersion && cachedLatestVersion !== LOCAL_VERSION), + webui_latest: isUpdateCheckDisabled() ? '' : cachedLatestVersion, + webui_update_available: isUpdateCheckDisabled() + ? false + : Boolean(LOCAL_VERSION && cachedLatestVersion && cachedLatestVersion !== LOCAL_VERSION), node_version: process.versions.node, } }