Files
hermes-ui/packages/server/src/config.ts
T
toor 4701bf0ad0 Phase 004: remove the desktop shell, website tooling, and bundled hermes CLI
- Drop all desktop/Electron branches, scripts, and UI (title bar, pets,
  desktop bridge); LAN endpoint kind is now web/custom only
- Replace the bundled hermes CLI with user-side installation: add
  GET /api/hermes/cli-status plus a HermesMissingView onboarding guide
- Remove the version-management UI (snapshots handled by git) and prune
  dead website/mcu/claude scripts and lockfile entries
2026-10-16 15:33:56 +08:00

78 lines
3.6 KiB
TypeScript

import { join, resolve } from 'path'
import { homedir } from 'os'
/**
* Web UI environment variables.
*
* Server/listen:
* - PORT: Web UI listen port. Default: 8648.
* - BIND_HOST: Web UI bind host. Default: 0.0.0.0.
* - CORS_ORIGINS: Comma/space-separated cross-origin allowlist. Default: same host only.
*
* Web UI storage:
* - HERMES_WEB_UI_HOME: Web UI data home for auth token, credentials, logs, DB, and default uploads.
* - HERMES_WEBUI_STATE_DIR: Compatibility alias for HERMES_WEB_UI_HOME.
* Default: join(homedir(), '.hermes-web-ui').
* - UPLOAD_DIR: Upload directory override. Default: join(HERMES_WEB_UI_HOME, 'upload').
* - dataDir: Development-only internal Web UI runtime data directory.
*
* Auth:
* - AUTH_TOKEN: Explicit bearer token. If unset, Web UI stores an auto-generated token under HERMES_WEB_UI_HOME.
* - HERMES_WEB_UI_AUTH_JWT_EXPIRES_IN: Username/password session JWT lifetime. Supports seconds or s/m/h/d suffixes. Default: 30d.
*
* Runtime behavior:
* - PROFILE: Initial Hermes profile name. Default: default.
* - HERMES_GATEWAY_URL / GATEWAY_URL: Explicit Hermes gateway upstream URL for proxy routes.
* - GATEWAY_HOST: Default Hermes gateway upstream host. Default: 127.0.0.1.
* - GATEWAY_PORT: Default Hermes gateway upstream port. Default: 8642.
* - HERMES_WEB_UI_DISABLE_GATEWAY_AUTOSTART: Disable Web UI gateway autostart checks and config-driven gateway start/stop reconciliation.
* - HERMES_WEB_UI_MANAGED_GATEWAY: Web UI-managed Hermes gateway handling. Enabled by default; set 0/false/off to use CLI start.
* - HERMES_WEB_UI_STOP_GATEWAYS_ON_SHUTDOWN: Whether Web UI shutdown also stops managed gateways.
* - HERMES_WEB_UI_DISABLE_MCP_AUTOINJECT: Disable Hermes Studio MCP config injection.
* - HERMES_WEB_UI_ALLOW_TRANSIENT_MCP_AUTOINJECT: Allow MCP injection when HERMES_WEB_UI_HOME is under a temp dir.
* - HERMES_LAN_DISCOVERY_ENABLED: Set false/0/off to disable UDP LAN discovery responder.
* - HERMES_LAN_DISCOVERY_HTTP_PORTS: HTTP ports to probe during UDP discovery scans. Default: 8648 plus current PORT.
* Discovery probes are sent to the fixed UDP port 48640 plus legacy mapped ports for compatibility.
* - WORKSPACE_BASE: Base directory for workspace browsing. Default: current user's home directory.
*
* Limits/logging:
* - MAX_DOWNLOAD_SIZE: Max file download size. Default: 200MB.
* - MAX_EDIT_SIZE: Max editable file size. Default: 10MB.
* - LOG_LEVEL: Server log level. Default: info.
* - BRIDGE_LOG_LEVEL: Bridge log level. Default: LOG_LEVEL or info.
*/
export function getListenHost(env: Record<string, string | undefined> = process.env): string {
const host = env.BIND_HOST?.trim()
return host || '0.0.0.0'
}
export function getWebUiHome(env: Record<string, string | undefined> = process.env): string {
const appHome = env.HERMES_WEB_UI_HOME?.trim() || env.HERMES_WEBUI_STATE_DIR?.trim()
return appHome ? resolve(appHome) : join(homedir(), '.hermes-web-ui')
}
export function shouldCreateWebUiDataDir(env: Record<string, string | undefined> = process.env): boolean {
return env.NODE_ENV !== 'production'
}
export function getCorsOrigins(env: Record<string, string | undefined> = process.env): string {
return env.CORS_ORIGINS?.trim() || ''
}
const appHome = getWebUiHome()
const remoteRelay = {
url: 'https://api.hermes-studio.ai',
}
export const config = {
port: parseInt(process.env.PORT || '8648', 10),
// Default to IPv4 for stable WSL/Windows browser access. Use BIND_HOST=:: explicitly for IPv6.
host: getListenHost(),
appHome,
uploadDir: process.env.UPLOAD_DIR || join(appHome, 'upload'),
dataDir: resolve(__dirname, '..', 'data'),
corsOrigins: getCorsOrigins(),
remoteRelay,
}