Files
Hermes-ui/packages/server/src/controllers/health.ts
T
ekkoandClaude Opus 4.6 1abe308742 feat: add Node.js version warning, fix provider URL detection, and add v0.4.4 changelog (#146)
- Display persistent warning bar when Node.js version < 23
- Fix provider model fetching to support non-v1 API versions (e.g. /v4)
- Add v0.4.4 changelog entries to frontend
- Bump version to 0.4.4

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-23 12:57:42 +08:00

56 lines
2.1 KiB
TypeScript

import * as hermesCli from '../services/hermes/hermes-cli'
import { getGatewayManagerInstance } from '../services/gateway-bootstrap'
import { config } from '../config'
declare const __APP_VERSION__: string
const LOCAL_VERSION = typeof __APP_VERSION__ !== 'undefined'
? __APP_VERSION__
: (() => { try { const { readFileSync } = require('fs'); const { resolve } = require('path'); return JSON.parse(readFileSync(resolve(__dirname, '../../package.json'), 'utf-8')).version } catch { return '0.0.0' } })()
let cachedLatestVersion = ''
export async function checkLatestVersion(): Promise<void> {
try {
const { readFileSync } = require('fs')
const pkg = JSON.parse(readFileSync(resolve(require('path').join(__dirname, '../../package.json')), 'utf-8'))
const name = pkg.name
const res = await fetch(`https://registry.npmjs.org/${name}/latest`, { signal: AbortSignal.timeout(10000) })
if (res.ok) {
const data = await res.json() as { version: string }
cachedLatestVersion = data.version
if (cachedLatestVersion !== LOCAL_VERSION) {
console.log(`Update available: ${LOCAL_VERSION}${cachedLatestVersion}`)
}
}
} catch { /* ignore */ }
}
export function startVersionCheck(): void {
setTimeout(checkLatestVersion, 5000)
setInterval(checkLatestVersion, 30 * 60 * 1000)
}
export async function healthCheck(ctx: any) {
const raw = await hermesCli.getVersion()
const hermesVersion = raw.split('\n')[0].replace('Hermes Agent ', '') || ''
let gatewayOk = false
try {
const mgr = getGatewayManagerInstance()
const upstream = mgr?.getUpstream() || config.upstream
const res = await fetch(`${upstream.replace(/\/$/, '')}/health`, { signal: AbortSignal.timeout(5000) })
gatewayOk = res.ok
} catch { }
ctx.body = {
status: gatewayOk ? 'ok' : 'error',
platform: 'hermes-agent',
version: hermesVersion,
gateway: gatewayOk ? 'running' : 'stopped',
webui_version: LOCAL_VERSION,
webui_latest: cachedLatestVersion,
webui_update_available: cachedLatestVersion && cachedLatestVersion !== LOCAL_VERSION,
node_version: process.versions.node,
}
}
function resolve(p: string) { return p }