Client SDK
Client WebSocket
Real-time WebSocket client
Client WebSocket#
Connect via WebSocket for real-time command execution and event subscriptions:
typescript
// Connect to WebSocketconst ws = await client.connect()ย // Execute commands over WebSocketconst result = await ws.execute('search', { query: 'laptop' })ย // Listen for eventsws.on('order.updated', (data) => { console.log('Order updated:', data)})ย // Disconnect when doneclient.disconnect()Retry & Cache
The client supports automatic retry with exponential backoff and an LRU response cache.
typescript
const client = await SurfClient.discover(url, { // Retry configuration retry: { maxAttempts: 3, backoffMs: 500, backoffMultiplier: 2, retryOn: [429, 502, 503, 504], },ย // Response caching (skips commands with sideEffects: true) cache: { ttlMs: 60_000, // 60s TTL maxSize: 100, // Max 100 cached entries },})ย // Execute โ automatically retries and cachesconst result = await client.execute('search', { query: 'laptop' })ย // Clear cache for a specific commandclient.clearCache('search')ย // Clear all cachesclient.clearCache()ย // Check for manifest updates (checksum comparison)const update = await client.checkForUpdates()if (update.changed) { console.log('Manifest updated:', update.manifest)}