Webchat: auto-start server and simplify config
This commit is contained in:
@@ -3,19 +3,18 @@
|
||||
Updated: 2025-12-08
|
||||
|
||||
## What shipped
|
||||
- A lightweight HTTP server now lives inside the Node relay (`clawdis webchat --port 18788`).
|
||||
- It binds to **127.0.0.1** only and serves:
|
||||
- `GET /webchat/info?session=<key>` → `{port, token, sessionId, initialMessages, basePath}` plus history from the relay’s session store.
|
||||
- The relay now starts a loopback-only web chat server automatically (default port **18788**, configurable via `webchat.port`).
|
||||
- Endpoints:
|
||||
- `GET /webchat/info?session=<key>` → `{port, sessionId, initialMessages, basePath}` plus history from the relay’s session store.
|
||||
- `GET /webchat/*` → static Web Chat assets.
|
||||
- `POST /webchat/rpc` → runs `clawdis agent --json` and returns `{ ok, payloads?, error? }`.
|
||||
- The macOS app embeds this UI in a WKWebView. In **remote mode** it first opens an SSH tunnel (`ssh -L <local>:127.0.0.1:<port>`) to the remote host, then loads `/webchat/info` through that tunnel.
|
||||
- Initial messages are preloaded from the relay’s session store, so remote sessions appear immediately.
|
||||
- Sending now goes over the HTTP `/webchat/rpc` endpoint (no more AgentRPC fallback).
|
||||
- Feature flag + port live in *Settings → Config → Web chat*. When disabled, the “Open Chat” menu entry is hidden.
|
||||
- The macOS app simply loads `http://127.0.0.1:<port>/webchat/?session=<key>` (or the SSH-forwarded port in remote mode). No Swift bridge is used for sends; all chat traffic stays inside the Node relay.
|
||||
- Initial messages are fetched from `/webchat/info`, so history appears immediately.
|
||||
- Enable/disable via `webchat.enabled` (default **true**); set the port with `webchat.port`.
|
||||
|
||||
## Security
|
||||
- Loopback only; remote access requires SSH port-forwarding.
|
||||
- Optional bearer token support is wired; tokens are returned by `/webchat/info` and accepted by `/webchat/rpc`.
|
||||
- No bearer token; the trust model is “local machine or your SSH tunnel”.
|
||||
|
||||
## Failure handling
|
||||
- Bootstrap errors show in-app (“Web chat failed to connect …”) instead of hanging.
|
||||
@@ -24,7 +23,7 @@ Updated: 2025-12-08
|
||||
## Dev notes
|
||||
- Static assets stay in `apps/macos/Sources/Clawdis/Resources/WebChat`; the server reads them directly.
|
||||
- Server code: `src/webchat/server.ts`.
|
||||
- CLI entrypoint: `clawdis webchat --json [--port N]`.
|
||||
- CLI entrypoint (optional): `clawdis webchat --json [--port N]` to query/start manually.
|
||||
- Mac glue: `WebChatWindow.swift` (bootstrap + tunnel) and `WebChatTunnel` (SSH -L).
|
||||
|
||||
## TODO / nice-to-haves
|
||||
|
||||
Reference in New Issue
Block a user