Files
hermes-agent/apps/desktop/src/lib/remote-url.ts
T
teknium1 087b2230c4 fix(desktop): accept scheme-less host:port in the remote gateway URL field
Users pasting a Tailscale IP or LAN host as 'host:port' (no http://) hit
either a hard 'URL is not valid' error in the main process or, worse, a
silent dead probe in the renderer: the ^https?:// gates in the settings
and first-run forms never fired, so the field sat idle with no feedback.

- normalizeRemoteBaseUrl() (electron/connection-config.ts) now prepends
  http:// when the input has no scheme:// prefix; explicit non-http
  schemes (ws://, ftp://) still reach the protocol check and get a clear
  rejection.
- New renderer twin coerceRemoteUrlScheme() (src/lib/remote-url.ts),
  wired into both probe gates (gateway-settings.tsx and
  first-run-remote-form.tsx) so the debounced /api/status probe, sign-in,
  test, and save all see the coerced URL.
- Tests for both sides (electron/connection-config.test.ts,
  src/lib/remote-url.test.ts).
2026-07-31 22:28:43 -07:00

23 lines
822 B
TypeScript

/**
* remote-url.ts
*
* Renderer-side twin of the scheme coercion in
* electron/connection-config.ts `normalizeRemoteBaseUrl()`. Users routinely
* paste scheme-less "host:port" (a Tailscale IP, a LAN hostname) into the
* remote-gateway URL field; without coercion the renderer's `^https?://`
* probe gates never fire and the field just sits idle with no feedback.
*
* Keep the opt-out regex in sync with the electron side: only a real
* `scheme://` prefix skips the http:// prepend, so explicit non-http schemes
* (ws://, ftp://) still reach main-process validation and get a clear error.
*/
export function coerceRemoteUrlScheme(rawUrl: string): string {
const value = String(rawUrl || '').trim()
if (!value || /^[a-z][a-z0-9+.-]*:\/\//i.test(value)) {
return value
}
return `http://${value}`
}