fix(gateway): respect NEXT_PUBLIC_GATEWAY_URL for hermes/demo adapter defaults#3
Conversation
… defaults resolveDefaultGatewayProfile() already honors NEXT_PUBLIC_GATEWAY_URL for the openclaw adapter via DEFAULT_UPSTREAM_GATEWAY_URL, but the demo/hermes branch returned a hardcoded "ws://localhost:18789", ignoring the env var. That literal got inlined into 5+ chunks in the .next/ bundle at build time, so split-host deployments (browser on laptop, adapter on a separate VM) had to post-build sed the bundle to make the WebSocket reachable. This switches the demo/hermes default to the same DEFAULT_UPSTREAM_GATEWAY_URL constant the openclaw branch uses. Single-host installs are unchanged (DEFAULT_UPSTREAM_GATEWAY_URL falls back to "ws://localhost:18789" when the env var is unset). Split-host installs now Just Work by exporting NEXT_PUBLIC_GATEWAY_URL=wss://your-host:18789 before `npm run build`. Pairs with PR fathah#2 (server-side HERMES_ADAPTER_HOST env var). Together they remove the last two brittle local patches needed to run a hermes-office instance on a LAN-served VM.
Build verificationRan the test plan locally on this branch ( Build #1 —
|
uzzaidev
left a comment
There was a problem hiding this comment.
Code Review — UzzAI Hermes Lab
Reviewed by: @uzzaidev (Hermes agentic review)
1. O que a mudança faz
Alinha o comportamento dos adapters demo e hermes com o adapter openclaw, substituindo o URL hardcoded ws://localhost:18789 pela constante DEFAULT_UPSTREAM_GATEWAY_URL que já respeita NEXT_PUBLIC_GATEWAY_URL.
2. Corretude da lógica
✅ Correta. DEFAULT_UPSTREAM_GATEWAY_URL já está definida no mesmo arquivo com fallback adequado:
const DEFAULT_UPSTREAM_GATEWAY_URL =
process.env.NEXT_PUBLIC_GATEWAY_URL || 'ws://localhost:18789'A mudança é mínima e cirúrgica — exatamente o necessário.
3. Riscos e edge cases
- Sem risco para single-host: fallback garante comportamento idêntico quando
NEXT_PUBLIC_GATEWAY_URLnão está definido. - Atenção em builds CI/CD:
NEXT_PUBLIC_*é inlined em build time pelo Next.js. Se o env var não estiver disponível no momento do build, o fallbacklocalhostserá compilado no bundle — comportamento esperado e documentado. - Edge case WSS vs WS: se o deploy usar TLS,
NEXT_PUBLIC_GATEWAY_URLdeve serwss://— responsabilidade do operador, não do código.
4. Backwards compatibility
✅ Totalmente compatível. Sem NEXT_PUBLIC_GATEWAY_URL, resultado é string idêntica à anterior.
5. Qualidade do código
✅ Comentário explicativo bem escrito e justificado. Uma linha de mudança efetiva com 5 linhas de contexto — proporção adequada para uma fix de segurança de configuração.
6. Veredito
✅ APPROVE
Fix legítima, bem documentada, zero risco de regressão para instalações single-host. Resolve um problema real de deploy split-host sem adicionar complexidade.
7. Score
9/10 — ponto a menos apenas pela ausência de teste automatizado, mas reconheço que testar comportamento de NEXT_PUBLIC_* em Next.js é não-trivial por ser compile-time.
Review gerada pelo pipeline agentic Hermes Lab — Claude Code via @uzzaidev
…ig-next 16.1.6→16.2.5
Summary
resolveDefaultGatewayProfile()already honorsNEXT_PUBLIC_GATEWAY_URLfor theopenclawadapter via theDEFAULT_UPSTREAM_GATEWAY_URLconstant defined a few lines above:…but the
demo/hermesbranch returned a hardcoded"ws://localhost:18789", ignoring the env var entirely. Because Next.js inlinesNEXT_PUBLIC_*env vars at build time, that literal got compiled into 5+ chunks in.next/, so split-host deployments (browser on laptop, adapter on a separate VM) had no way to make the client-side WebSocket reach the adapter without a post-buildsedof the bundle.This is a one-line behavioral fix: switch the
demo/hermesdefault to the sameDEFAULT_UPSTREAM_GATEWAY_URLconstant theopenclawbranch uses.Diff
Why this matters
Real-world deployment context: hermes-agent + hermes-office adapter run on a Hyper-V VM at `192.168.x.y`. The Studio UI is served via a Caddy reverse-proxy on the same VM at `hermes.andrea-house.com:3000`. The browser opens that URL on a separate workstation. Without this change, the browser-side bundle tries to connect to `ws://localhost:18789` — which is the workstation's localhost, not the VM's — and fails with
ECONNREFUSED. The only workaround was sed-ing every `.next/` chunk on every rebuild, which is what we documented at hermes-vps:scripts/hermes-office-restore-patches.sh.This change makes the env-var path Just Work for
hermesanddemoadapters, the same way it already does foropenclaw.Backwards compatibility
Fully backwards compatible:
DEFAULT_UPSTREAM_GATEWAY_URLfalls back to\"ws://localhost:18789\"when `NEXT_PUBLIC_GATEWAY_URL` is unset, so single-host installs see the exact same string as before.Pairs with
#2 — adds server-side
HERMES_ADAPTER_HOSTenv var so the adapter can bind on a non-loopback NIC. Together, the two PRs remove the last brittle local patches needed to run hermes-office on a LAN-served VM.Test plan
NEXT_PUBLIC_GATEWAY_URLunset,DEFAULT_UPSTREAM_GATEWAY_URLfalls back to\"ws://localhost:18789\"exactly as beforeNEXT_PUBLIC_GATEWAY_URL=wss://hermes.andrea-house.com:18789, the constant resolves to that value at build time and gets inlined into thehermes/demoadapter defaultopenclawbranch behavior is unchanged (it already usedDEFAULT_UPSTREAM_GATEWAY_URL)🤖 Generated with Claude Code