|
| 1 | +import { createLoopSystem, parseLoopYaml } from "@loop-engine/sdk"; |
| 2 | +import { OpenClawEventBus } from "@loop-engine/adapter-openclaw"; |
| 3 | +// This example demonstrates @loop-engine/adapter-openclaw directly. |
| 4 | +// The other examples show generic Loop Engine patterns that work |
| 5 | +// alongside OpenClaw — this one shows the adapter-specific integration. |
| 6 | +const loop = parseLoopYaml(` |
| 7 | +loopId: openclaw.change.approval |
| 8 | +version: "1.0.0" |
| 9 | +name: OpenClaw Change Approval |
| 10 | +initialState: requested |
| 11 | +states: |
| 12 | + - { stateId: requested, label: Requested } |
| 13 | + - { stateId: pending_approval, label: Pending Approval } |
| 14 | + - { stateId: completed, label: Completed, terminal: true } |
| 15 | +transitions: |
| 16 | + - { transitionId: submit_change, from: requested, to: pending_approval, signal: submit_change, allowedActors: [automation] } |
| 17 | + - { transitionId: approve, from: pending_approval, to: completed, signal: approve, allowedActors: [human] } |
| 18 | +`); |
| 19 | +async function main() { |
| 20 | + const { engine, eventBus } = await createLoopSystem({ loops: [loop] }); |
| 21 | + const openclawBus = new OpenClawEventBus({ channel: "ops-approvals", target: "openclaw://channel/sre", approvalStates: ["pending_approval"], events: ["loop.transition.executed", "loop.completed"] }); |
| 22 | + const unsubscribe = eventBus.subscribe(async (event) => openclawBus.emit(event)); |
| 23 | + await engine.startLoop({ loopId: "openclaw.change.approval" as never, aggregateId: "CHG-1001" as never, actor: { type: "automation", id: "deploy-bot" as never } }); |
| 24 | + await engine.transition({ aggregateId: "CHG-1001" as never, transitionId: "submit_change" as never, actor: { type: "automation", id: "deploy-bot" as never } }); |
| 25 | + await engine.transition({ aggregateId: "CHG-1001" as never, transitionId: "approve" as never, actor: { type: "human", id: "sre-oncall" as never } }); |
| 26 | + unsubscribe(); |
| 27 | + openclawBus.disconnect(); |
| 28 | +} |
| 29 | +main().catch(console.error); |
0 commit comments