npm package: @noticlaw/openclaw-client
Description: OpenClaw client SDK for connecting agents to NotiClaw Dashboard
Author: NotiClaw Team
Latest version: 1.1.1

# @noticlaw/openclaw-client

Client SDK for connecting OpenClaw agents to the NotiClaw Dashboard.

## Installation

```bash
npm install @noticlaw/openclaw-client
```

## Quick Start

```typescript
import { NotiClawClient } from '@noticlaw/openclaw-client';
import { readFileSync } from 'fs';

// Create client with your API key
const client = new NotiClawClient({
  // Defaults to https://noticlaw.com if omitted
  serverUrl: 'https://noticlaw.com',
  apiKey: 'moc_your_api_key_here',
});

// Listen for events from humans
client.on('human:message', (message) => {
  console.log(`Message from ${message.from}: ${message.content}`);
});

client.on('task:assigned', (task) => {
  console.log(`New task: ${task.title}`);
});

client.on('command', (cmd) => {
  if (cmd.type === 'stop') {
    // Handle stop command
  }
});

// Connect with your bootstrap files
await client.connect({
  soulMd: readFileSync('./SOUL.md', 'utf-8'),
  agentsMd: readFileSync('./AGENTS.md', 'utf-8'),
});
```

## API Reference

### Constructor

```typescript
new NotiClawClient({
  serverUrl?: string,      // URL of the NotiClaw Dashboard server (default: https://noticlaw.com)
  apiKey: string,         // API key from dashboard
  autoReconnect?: boolean, // Auto-reconnect (default: true)
  reconnectInterval?: number // Reconnect interval in ms (default: 5000)
})
```

### Methods

#### `connect(bootstrapFiles?)`
Connect to the dashboard server.

```typescript
await client.connect({
  soulMd: '...', // Content of SOUL.md
  agentsMd: '...', // Content of AGENTS.md
});
```

#### `disconnect()`
Disconnect from the server.

#### `updateStatus(status, contextTokens?)`
Update agent status.

```typescript
client.updateStatus('busy');
client.updateStatus('online', 50000); // with context tokens
```

#### `reportRunStart(runId, sessionKey)`
Report that a run has started.

```typescript
client.reportRunStart('run-123', 'session-key');
```

#### `reportRunProgress(runId, progress)`
Report run progress.

```typescript
client.reportRunProgress('run-123', { tokens: 1000 });
client.reportRunProgress('run-123', {
  toolCall: { id: 'tc-1', name: 'search', status: 'completed' }
});
```

#### `reportRunComplete(runId, status, error?)`
Report that a run has completed.

```typescript
client.reportRunComplete('run-123', 'completed');
client.reportRunComplete('run-123', 'error', 'Something went wrong');
```

#### `createTask(title, description?, options?)`
Create a task visible in the dashboard.

```typescript
client.createTask('Review code changes', 'Please review the PR', {
  assignToHuman: true,
  priority: 'high'
});
```

#### `postNote(content, pinned?)`
Post a note to the dashboard.

```typescript
client.postNote('Task completed successfully!');
client.postNote('Important update', true); // pinned
```

### Events

```typescript
client.on('connected', ({ agentId }) => { ... });
client.on('disconnected', () => { ... });
client.on('error', ({ code, message }) => { ... });
client.on('human:message', ({ from, content }) => { ... });
client.on('task:assigned', ({ taskId, title, description }) => { ... });
client.on('command', ({ type }) => { ... }); // 'stop' | 'reset' | 'compact'
```

## Integration with OpenClaw

To integrate with your OpenClaw agent, add the client initialization to your agent's bootstrap:

```typescript
// In your OpenClaw agent setup
import { NotiClawClient } from '@noticlaw/openclaw-client';

const noticlaw = new NotiClawClient({
  serverUrl: process.env.NOTICLAW_SERVER_URL ?? 'https://noticlaw.com',
  apiKey: process.env.NOTICLAW_API_KEY,
});

// Connect on agent start
await noticlaw.connect({
  soulMd: agent.getSoulMd(),
  agentsMd: agent.getAgentsMd(),
});

// Hook into agent lifecycle
agent.on('run:start', (run) => {
  noticlaw.reportRunStart(run.id, run.sessionKey);
});

agent.on('run:complete', (run) => {
  noticlaw.reportRunComplete(run.id, run.status, run.error);
});

// Handle human commands
noticlaw.on('command', (cmd) => {
  if (cmd.type === 'stop') {
    agent.abort();
  } else if (cmd.type === 'reset') {
    agent.resetSession();
  }
});
```

## License

MIT