mirror of
https://github.com/Egonex-AI/Understand-Anything.git
synced 2026-06-22 10:58:03 +08:00
feat(dashboard): detect remote session and ask for host before launch
The env vars alone don't help users on the agent-driven /understand-dashboard path, since the agent launches Vite with localhost defaults. Add a detection + prompt step to the skill: when an SSH/remote session is detected, ask the user which hostname/IP they'll browse from, then launch with UNDERSTAND_HOST=0.0.0.0 and UNDERSTAND_ALLOWED_HOSTS=<host>, and report the URL with that host.
This commit is contained in:
@@ -77,21 +77,57 @@ Start the Understand Anything dashboard to visualize the knowledge graph for the
|
||||
cd <plugin-root> && pnpm --filter @understand-anything/core build
|
||||
```
|
||||
|
||||
5. Start the Vite dev server pointing at the project's knowledge graph:
|
||||
5. **Detect whether this is a remote / headless session.** A localhost-only bind
|
||||
(the default) cannot be reached from the user's browser when Vite runs on a
|
||||
different machine, and Vite rejects domain-name `Host` headers with
|
||||
`Blocked request. This host ("…") is not allowed.` Check for a remote session:
|
||||
```bash
|
||||
[ -n "$SSH_CONNECTION" ] || [ -n "$SSH_TTY" ] || [ -n "$SSH_CLIENT" ] && echo remote || echo local
|
||||
```
|
||||
- If the result is `local`, skip to step 6 and launch with defaults.
|
||||
- If the result is `remote`, **ask the user** which host they will open the
|
||||
dashboard from, e.g.:
|
||||
```
|
||||
It looks like you're running on a remote machine. Which hostname or IP
|
||||
will you open the dashboard from in your browser?
|
||||
(e.g. mybox.example.com or 203.0.113.5 — press enter to keep localhost-only)
|
||||
```
|
||||
Remember their answer as `<remote-host>`. If they skip / press enter, treat
|
||||
this as a local session and launch with defaults.
|
||||
|
||||
6. Start the Vite dev server pointing at the project's knowledge graph.
|
||||
|
||||
**Local session** (default — binds to localhost only):
|
||||
```bash
|
||||
cd <dashboard-dir> && GRAPH_DIR=<project-dir> npx vite --host 127.0.0.1
|
||||
```
|
||||
|
||||
**Remote session** (user provided `<remote-host>` in step 5):
|
||||
```bash
|
||||
cd <dashboard-dir> && GRAPH_DIR=<project-dir> \
|
||||
UNDERSTAND_HOST=0.0.0.0 \
|
||||
UNDERSTAND_ALLOWED_HOSTS=<remote-host> \
|
||||
npx vite
|
||||
```
|
||||
`UNDERSTAND_HOST=0.0.0.0` accepts connections from outside localhost, and
|
||||
`UNDERSTAND_ALLOWED_HOSTS` whitelists the `Host` header so Vite stops blocking
|
||||
it. The one-time access token still gates every data endpoint.
|
||||
|
||||
Run this in the background so the user can continue working.
|
||||
|
||||
6. **Capture the access token URL from the server output.** The Vite server prints a line like:
|
||||
7. **Capture the access token URL from the server output.** The Vite server prints a line like:
|
||||
```
|
||||
🔑 Dashboard URL: http://127.0.0.1:<PORT>?token=<TOKEN>
|
||||
```
|
||||
Extract the full URL including the `?token=` parameter. The token is required to access the knowledge graph data — without it the dashboard will show an "Access Token Required" gate.
|
||||
Extract the `?token=` value — it is required to access the knowledge graph
|
||||
data; without it the dashboard shows an "Access Token Required" gate. The
|
||||
printed line always shows `127.0.0.1`; for a remote session substitute
|
||||
`<remote-host>` for the host portion when reporting the URL.
|
||||
|
||||
7. Report to the user, including the full tokenized URL:
|
||||
8. Report to the user, including the full tokenized URL (use `<remote-host>`
|
||||
instead of `127.0.0.1` for a remote session):
|
||||
```
|
||||
Dashboard started at http://127.0.0.1:<PORT>?token=<TOKEN>
|
||||
Dashboard started at http://<host>:<PORT>?token=<TOKEN>
|
||||
Viewing: <project-dir>/.understand-anything/knowledge-graph.json
|
||||
|
||||
The dashboard is running in the background. Press Ctrl+C in the terminal to stop it.
|
||||
|
||||
Reference in New Issue
Block a user