Skip to content

relay: allow blank gateway token + polished WebLLM worker page - #332

Merged
FMXExpress merged 1 commit into
mainfrom
claude/relay-blank-token-and-polished-webllm
Jun 22, 2026
Merged

FMXExpress merged 1 commit into
mainfrom
claude/relay-blank-token-and-polished-webllm

Conversation

@FMXExpress

Copy link
Copy Markdown
Owner

Summary

Two unrelated fixes a user surfaced together.

Fix 1 — pasclaw relay --gateway-token no longer required

The gateway accepts unauth'd traffic when Cfg.Gateway.Token is empty (the historical pre-PR-#246 shape), but the worker refused to start without a token — turning a valid pairing into a CLI rejection. Dropped the existence check; the four header / query-param emission sites (PostResponse, Indy SSE GET, NetHTTP SSE GET, browser snippet) now skip Authorization entirely when Ctx.Token = ''.

Smoke-tested: gateway with no token configured + pasclaw relay --gateway-url http://127.0.0.1:18900 (no --gateway-token) → worker registers and /v1/relay/status reports it.

Fix 2 — Browser snippet replaced with a polished standalone HTML page

Styled to match the PasClaw webui — same --bg/--bg2/--fg/--cyan/--mut/--line CSS variables, JetBrains Mono font, glow on focus, pill buttons.

  • Model picker (the user's ask): dropdown grouped by VRAM footprint covering 11 curated MLC prebuilt configs:
    • Tiny (under 1B): Llama 3.2 1B, Qwen 2.5 1.5B, Qwen 2.5 0.5B
    • Small (2-3B): Llama 3.2 3B, Qwen 2.5 3B, Phi 3.5 mini, Gemma 2 2B, Hermes 3 (Llama 3.2 3B) — tool-call friendly
    • Medium (7-8B): Llama 3.1 8B, Qwen 2.5 7B, DeepSeek R1 Distill (Qwen 7B) — reasoning
  • First option is a disabled placeholder so connecting without picking is impossible.
  • Connect / Disconnect lifecycle: download + warm engine with a live progress bar (initProgressCallback), then open SSE. Each job logs with timestamp + colour (ok/warn/err) and bumps a "N served" counter.
  • Token blank-friendly: only adds Authorization header / ?token= query param when the token field is non-empty (matches Fix 1).
  • Standalone: one <html>, ESM import via esm.run, no toolchain. Save as relay.html, open in any browser, click Connect.

Same TDZ pattern as before — RELAY_WEBLLM_MODELS moved above the boot block alongside the other relay-tab state.

Test plan

  • make all clean.
  • Blank-token live smoke: gateway with no token, pasclaw relay --gateway-url ... --worker-id notoken-test (no token flag) — worker registers, connected_workers: 1.
  • jsdom render check: relay tab activates without errors, 5 snippet blocks, browser snippet is 11.2 KB starting with <!DOCTYPE html>, contains all 11 model ids + CreateMLCEngine + EventSource + Disconnect + if (tok) conditional.
  • Manual: save the rendered snippet, open in a browser, pick Llama 3.2 1B, click Connect, dispatch a chat through the gateway — end-to-end (out of band, requires a browser with WebGPU).

🤖 Generated with Claude Code

https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon


Generated by Claude Code

Two unrelated fixes a user surfaced together.

1. pasclaw relay --gateway-token is no longer required.
   The gateway accepts unauth'd traffic when Cfg.Gateway.Token is
   empty (the historical pre-PR-#246 shape), but the worker
   refused to start without a token, turning a valid pairing into
   a CLI rejection. Dropped the existence check; the four header /
   query-param emission sites (PostResponse, Indy SSE GET, NetHTTP
   SSE GET, and the browser snippet) now skip Authorization
   entirely when Ctx.Token = ''. Smoke-tested against a gateway
   with no token configured -- worker registers and the status
   endpoint reports it.

2. Browser/WebLLM snippet replaced with a polished standalone HTML
   page styled to match the PasClaw webui.
   - Dark navy gradient + cyan accents (same CSS variables the
     panel uses: --bg/--bg2/--fg/--cyan/--mut/--line).
   - JetBrains Mono font, glow effects on focused inputs,
     pill-shaped buttons with the same primary/secondary states
     as the webui's nav.
   - Curated model dropdown grouped by VRAM footprint (Tiny <1B
     / Small 2-3B / Medium 7-8B) covering Llama 3.1/3.2, Qwen 2.5,
     Phi 3.5, Gemma 2, DeepSeek R1 Distill, Hermes 3 -- 11 entries
     pulled from MLC's prebuilt config.ts. First option is a
     disabled placeholder so the user is forced to pick before
     Connect lights up. Hermes 3 entry called out as tool-call
     friendly; DeepSeek R1 entry called out as reasoning.
   - Connect / Disconnect lifecycle: clicking Connect downloads +
     warms the WebLLM engine with a live progress bar (driven by
     initProgressCallback), then opens the SSE poll. Each
     dispatched job logs an entry with timestamp + status colour
     (ok/warn/err) and bumps a "N served" counter. Disconnect
     closes the EventSource and re-enables Connect.
   - Token blank-friendly: only adds Authorization header / ?token=
     query param when the token field is non-empty, matching the
     CLI fix above. Worker id pre-filled with a random tab-XXXXXXXX
     value so the operator can paste-and-go without a name clash.
   - Standalone: one <html>, ESM import for web-llm via esm.run,
     no toolchain. Save as relay.html, open in any browser, click
     Connect. Closing the tab disconnects.

   Same TDZ trap as before -- the RELAY_WEBLLM_MODELS const was
   declared inside the render path but referenced by a function
   the /#relay deep-link boot path invokes before the const
   initializer runs. Moved it up to the relay-tab state block
   above the boot block (where relayTimer / RELAY_TOKEN_PLACEHOLDER
   live for the same reason).

webui.res regenerated.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon
@FMXExpress
FMXExpress merged commit facbd27 into main Jun 22, 2026
khongten001 pushed a commit to khongten001/PasClaw that referenced this pull request Jul 13, 2026
User feedback on the standalone-HTML snippet from PR FMXExpress#332:

  "the html relay code should just be built into that relay tab? but
   I don't think it should import any remote stuff [...] unless the
   user clicks the button to start the webllm. like maybe they never
   use the relay setup at all, wouldn't want to load any third party
   stuff they never use."

Both legit. Reworked the Relay tab:

- New "In-browser worker" section directly inside the tab body,
  between the config grid and the snippet list. Has the same model
  picker + Worker id input + Connect / Disconnect buttons + live
  progress bar + status dot + scrolling colour-coded log the
  standalone page had, styled with the same CSS variables the rest
  of the relay tab uses so it visually fits in.

- WebLLM is loaded via `await import("https://esm.run/@mlc-ai/web-llm")`
  inside the Connect button's click handler. The static `import {
  CreateMLCEngine } from ...` at module top is gone -- a user who
  never opens the Relay tab, or opens it but doesn't click Connect,
  pays zero third-party bandwidth. Browsers cache the module after
  the first fetch so subsequent Connects are instant.

- Disconnect drops the engine reference (browser GCs the WASM) and
  closes the EventSource; model weights stay in IndexedDB so the
  next Connect skips the download.

- beforeunload closes the EventSource so the gateway sweeps the
  worker from /v1/relay/status promptly rather than waiting for the
  keepalive timeout.

- Standalone-HTML snippet ("Browser worker (WebLLM, ESM)") removed
  from the code-block snippet list -- the in-tab worker covers the
  same use case and the rendered HTML for the page was ~11KB of dead
  weight on every webui load. The remaining snippets (CLI flags,
  env vars, Python, cog-relay) are still useful: those run on
  different host platforms.

- buildBrowserSnippet() helper deleted (~250 LOC).

- Outer "Connect a worker" heading renamed to "Connect a worker
  from another host" to differentiate from the new in-tab option.

jsdom smoke verified all of:
  - in-browser worker UI present
  - no eager static `import { CreateMLCEngine } from esm.run` anywhere
  - dynamic `await import(esm.run)` is present (gated behind click)
  - tab renders with zero runtime errors
  - model dropdown populated (11 curated entries + placeholder)
  - Connect enabled / Disconnect disabled at start
  - code-block snippet count down from 5 to 4

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants