feat(onboard): print Control UI chat URLs with embedded gateway token#906
feat(onboard): print Control UI chat URLs with embedded gateway token#906cv merged 1 commit intoNVIDIA:mainfrom
Conversation
📝 WalkthroughWalkthroughAdded logic to the onboarding process that retrieves a gateway authentication token from the sandbox by downloading and parsing Changes
Sequence DiagramsequenceDiagram
participant Onboard as Onboarding Process
participant OpenShell as openshell CLI
participant Sandbox as Sandbox
participant Parser as JSON Parser
participant Dashboard as Dashboard
Onboard->>OpenShell: sandbox download
OpenShell->>Sandbox: Request openclaw.json
Sandbox-->>OpenShell: Download files
OpenShell-->>Onboard: Return download output
Onboard->>Parser: Recursively locate openclaw.json
Parser-->>Onboard: File path found
Onboard->>Parser: Extract cfg.gateway.auth.token
Parser-->>Onboard: Token value (or null on failure)
alt Token Retrieved
Onboard->>Dashboard: Pass token to printDashboard()
Dashboard->>Dashboard: Generate URLs with `#token`=<token>
Dashboard-->>Onboard: Display Control UI URLs
else Token Unavailable
Onboard->>Dashboard: Pass null token
Dashboard->>Dashboard: Generate fallback URL
Dashboard-->>Onboard: Display fallback URL + manual retrieval instructions
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@bin/lib/onboard.js`:
- Around line 2187-2200: The function buildControlUiChatUrls embeds the raw
token into the URL fragment, which can produce malformed URLs when the token
contains special characters; update the logic in buildControlUiChatUrls to
URL-encode the token (use encodeURIComponent on token before constructing
hash/pathChat) so the fragment becomes `#token=<encoded>` and all constructed
URLs use this encoded token (keep references to CONTROL_UI_CHAT_PATH,
CONTROL_UI_PORT and the chatUi handling intact).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: c88cdc80-206d-463d-a93f-9741fa09da0e
📒 Files selected for processing (1)
bin/lib/onboard.js
| function buildControlUiChatUrls(token) { | ||
| const hash = token ? `#token=${token}` : ""; | ||
| const pathChat = `${CONTROL_UI_CHAT_PATH}${hash}`; | ||
| const bases = [ | ||
| `http://127.0.0.1:${CONTROL_UI_PORT}`, | ||
| `http://localhost:${CONTROL_UI_PORT}`, | ||
| ]; | ||
| const chatUi = (process.env.CHAT_UI_URL || "").trim().replace(/\/$/, ""); | ||
| const urls = bases.map((b) => `${b}${pathChat}`); | ||
| if (chatUi && /^https?:\/\//i.test(chatUi) && !bases.includes(chatUi)) { | ||
| urls.push(`${chatUi}${pathChat}`); | ||
| } | ||
| return [...new Set(urls)]; | ||
| } |
There was a problem hiding this comment.
URL-encode the token before embedding in the URL fragment.
If the gateway token contains URL-special characters (#, ?, &, =, spaces, etc.), the resulting URL will be malformed. Use encodeURIComponent() to ensure the token is safely embedded.
🔧 Proposed fix
function buildControlUiChatUrls(token) {
- const hash = token ? `#token=${token}` : "";
+ const hash = token ? `#token=${encodeURIComponent(token)}` : "";
const pathChat = `${CONTROL_UI_CHAT_PATH}${hash}`;📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| function buildControlUiChatUrls(token) { | |
| const hash = token ? `#token=${token}` : ""; | |
| const pathChat = `${CONTROL_UI_CHAT_PATH}${hash}`; | |
| const bases = [ | |
| `http://127.0.0.1:${CONTROL_UI_PORT}`, | |
| `http://localhost:${CONTROL_UI_PORT}`, | |
| ]; | |
| const chatUi = (process.env.CHAT_UI_URL || "").trim().replace(/\/$/, ""); | |
| const urls = bases.map((b) => `${b}${pathChat}`); | |
| if (chatUi && /^https?:\/\//i.test(chatUi) && !bases.includes(chatUi)) { | |
| urls.push(`${chatUi}${pathChat}`); | |
| } | |
| return [...new Set(urls)]; | |
| } | |
| function buildControlUiChatUrls(token) { | |
| const hash = token ? `#token=${encodeURIComponent(token)}` : ""; | |
| const pathChat = `${CONTROL_UI_CHAT_PATH}${hash}`; | |
| const bases = [ | |
| `http://127.0.0.1:${CONTROL_UI_PORT}`, | |
| `http://localhost:${CONTROL_UI_PORT}`, | |
| ]; | |
| const chatUi = (process.env.CHAT_UI_URL || "").trim().replace(/\/$/, ""); | |
| const urls = bases.map((b) => `${b}${pathChat}`); | |
| if (chatUi && /^https?:\/\//i.test(chatUi) && !bases.includes(chatUi)) { | |
| urls.push(`${chatUi}${pathChat}`); | |
| } | |
| return [...new Set(urls)]; | |
| } |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@bin/lib/onboard.js` around lines 2187 - 2200, The function
buildControlUiChatUrls embeds the raw token into the URL fragment, which can
produce malformed URLs when the token contains special characters; update the
logic in buildControlUiChatUrls to URL-encode the token (use encodeURIComponent
on token before constructing hash/pathChat) so the fragment becomes
`#token=<encoded>` and all constructed URLs use this encoded token (keep
references to CONTROL_UI_CHAT_PATH, CONTROL_UI_PORT and the chatUi handling
intact).
There was a problem hiding this comment.
@HagegeR confirm this either cannot be an issue or let's encodeURIComponent
There was a problem hiding this comment.
Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!
There was a problem hiding this comment.
I don't know how the token is generated, but it worked for my use case, we can try, but it might be overkill
|
Pretty neat UX! |
Summary
After onboard completes, print clickable Control UI URLs that include the gateway auth token so users can copy-paste them directly into a browser (port-forwarded). When the token download fails, fall back to manual instructions.
Related Issue
Related to #20 — this PR complements the remote dashboard access fix by providing token-embedded URLs that work over SSH port-forwarding. See also #114 which addresses the gateway binding side.
Changes
bin/lib/onboard.js:CONTROL_UI_PORT/CONTROL_UI_CHAT_PATHconstantsfindOpenclawJsonPath()— recursive search foropenclaw.jsonin download dirfetchGatewayAuthTokenFromSandbox()— downloadsopenclaw.jsonfrom the sandbox to extractgateway.auth.tokenbuildControlUiChatUrls()— generateshttp://127.0.0.1andhttp://localhostURLs with#token=hashprintDashboard()— show Control UI URLs with embedded token, or fallback instructionsType of Change
Testing
npx prek run --all-filespassesnpm testpassesChecklist
General
git log --show-signature).Code Changes
npx prek run --all-filesauto-fixes formatting.