Now AgentWebSocketClient connects to
ws(s)://<BACKEND_HOST>/ws/agent, so it works both locally and in Preview /
Production environments.
Set NEXT_PUBLIC_BACKEND_URL (e.g. https://saarthi-backend.vercel.app)
when the backend isn’t on the same origin.
To configure the generation, complete these steps:
Below is a small patch that (1) makes the WebSocket URL environment-driven (falling back to the current origin), (2) automatically selects ws:// or wss:// according to the page protocol, (3) queues outbound messages until the socket is OPEN, and (4) surfaces real error text instead of the generic {"isTrusted":true} blob.
[V0_FILE]tsx:file="lib/websocket-agent-client.tsx"
... shell ...
[V0_FILE]typescriptreact:file="app/agent/page.tsx"
... shell ...Why this fixes the issue • Front-end now derives wss:// when your site runs on HTTPS, avoiding mixed-content rejections. • It stops hard-coding localhost:8000, working both locally and on Vercel (set NEXT_PUBLIC_BACKEND_URL to your backend host). • Outgoing queries no longer race the connection handshake; they queue until ready. • Real error messages bubble up to the UI/log. After deploying, ensure: ```bash # Vercel / .env NEXT_PUBLIC_BACKEND_URL=https://your-backend-domain.com ``` Locally you can still rely on the default (“/” ➜ same host) or: ```bash NEXT_PUBLIC_BACKEND_URL=http://localhost:8000 npm run dev ``` Then revisit /agent —the socket should connect without the {"isTrusted": true} error. To configure the generation, complete these steps: <StepsCard steps={[{type: "add-env-var", stepName: "NEXT_PUBLIC_BACKEND_URL"}]} />
You can send messages while the preview loads