$ show openclaw/cookbook
This repository is a cookbook of runnable examples for the OpenClaw SDK. It contains two layers: small one-concept recipes (e.g., run-an-agent, stream-events, cancel-a-run) and standalone starter apps (quickstart Node app, coding-agent CLI, agent-workbench React app, run-board React dashboard). The code demonstrates SDK workflows such as starting runs, streaming normalized events, cancelling work, reusing sessions, checking model status, and testing with an in-memory transport. The architecture is modular: recipes are self-contained TypeScript files with shared configuration helpers, and SDK examples are independent packages that can be copied out and adapted. The repository includes comprehensive tests, CI checks, and a workspace SDK shim for local validation without a live Gateway. It is actively maintained with modern dependencies (TypeScript 7, Node 22, pnpm 10.34.5) and follows strict formatting and linting rules.
The LLM identified 3 files worth highlighting for reuse:
Provides a reusable `redactSensitiveOutput` function that recursively masks fields containing 'token', 'password', 'secret', 'authorization', or ending in 'key' (case-insensitive). It also handles circular references via a WeakSet. This function is used across all recipes and SDK examples to prevent credential leakage in console output. It can be extracted and applied to any JSON serialization where sensitive fields need to be redacted.
Implements the `OpenClawTransport` interface with an in-memory transport that records RPC calls and returns canned responses. This pattern allows testing SDK-dependent application code without a real Gateway. The transport is a simple class that can be instantiated and passed to the OpenClaw constructor. It demonstrates how to create a test double for the SDK's transport layer, which is a reusable pattern for any SDK that uses a transport abstraction.
A well-crafted interactive CLI that handles cancellation during startup, retry on failure, and graceful shutdown. It uses a `runCreated` promise to retain cancellation requests made before the run handle is available, and a `cancellation` promise to avoid duplicate cancellation attempts. The CLI also handles Ctrl+C, EOF, and slash commands. This pattern for managing asynchronous cancellation in a CLI is non-obvious and can be reused in any interactive tool that needs to cancel long-running operations.