Packages
@loop-engine/adapter-openclaw
Overview
@loop-engine/adapter-openclaw wraps an internal event bus and forwards selected loop events to OpenClaw over its WebSocket gateway control plane.
Install
1npm install @loop-engine/adapter-openclaw wsPrerequisites
- OpenClaw gateway reachable at
ws://127.0.0.1:18789 - Configured OpenClaw channel and target destination
createLoopSystem usage
1import { createLoopSystem } from '@loop-engine/sdk'2import { OpenClawEventBus } from '@loop-engine/adapter-openclaw'3import { replenishmentLoop } from './loops/replenishment'4 5const bus = new OpenClawEventBus({6 channel: 'whatsapp',7 target: '+15551234567',8 events: ['loop.transition.executed', 'loop.completed'],9 approvalStates: ['PENDING_BUYER_APPROVAL']10})11 12const system = await createLoopSystem({ loops: [replenishmentLoop], eventBus: bus })OpenClawAdapterOptions
1interface OpenClawAdapterOptions {2 gatewayUrl?: string "cmt">// default: ws://127.0.0.1:187893 channel: string4 target: string5 accountId?: string6 events?: string[] "cmt">// default: ['loop.transition.executed','loop.completed','loop.guard.failed']7 loopIds?: string[] "cmt">// default: []8 approvalStates?: string[] "cmt">// default: []9 inner?: EventBus "cmt">// default: new InMemoryEventBus()10 autoReconnect?: boolean "cmt">// default: true11 reconnectDelay?: number "cmt">// default: 500012}Approval state detection
The adapter marks a transition event as approval-required when toState matches PENDING|APPROVAL unless explicit approvalStates are configured.
Lifecycle cleanup
Call disconnect() during shutdown to stop reconnect timers and close the current socket cleanly.
Related example
See OpenClaw Integration for the end-to-end approval flow.