openclaw-ws
v0.1.1
Published
OpenClaw WebSocket client and protocol
Maintainers
Readme
openclaw-ws
OpenClaw WebSocket client and protocol for browser environments.
Features
- WebSocket client with auto-reconnect
- Device identity and authentication (Ed25519)
- Device token caching
- Protocol type definitions
- Request/response and event handling
Installation
pnpm add openclaw-wsUsage
import { GatewayBrowserClient } from "openclaw-ws";
const client = new GatewayBrowserClient({
url: "ws://localhost:18789",
token: "your-token",
clientName: "webchat-ui",
mode: "webchat",
onHello: (hello) => {
console.log("Connected:", hello);
},
onEvent: (evt) => {
console.log("Event:", evt.event, evt.payload);
},
onClose: (info) => {
console.log("Closed:", info);
},
});
client.start();
// Make a request
const response = await client.request("chat.history", {
sessionKey: "session-key",
});
client.stop();API
GatewayBrowserClient
start()- Start the connectionstop()- Stop the connectionconnected- Get connection statusrequest<T>(method, params)- Make a request
Device Auth
loadOrCreateDeviceIdentity()- Load or create device identitysignDevicePayload(privateKey, payload)- Sign a payloadloadDeviceAuthToken(params)- Load cached tokenstoreDeviceAuthToken(params)- Store tokenclearDeviceAuthToken(params)- Clear token
Protocol
GATEWAY_CLIENT_IDS- Client ID constantsGATEWAY_CLIENT_MODES- Client mode constantsConnectErrorDetailCodes- Error code constants- Various normalization utilities
