File size: 5,596 Bytes
3380376
63ed3a7
3380376
63ed3a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3380376
63ed3a7
 
3380376
63ed3a7
 
 
 
 
 
 
 
 
 
 
3380376
63ed3a7
3380376
63ed3a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3380376
63ed3a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3380376
63ed3a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3380376
63ed3a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3380376
 
63ed3a7
 
 
3380376
63ed3a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# RobotHub Inference Server TypeScript Client

A TypeScript client for the RobotHub Inference Server, providing ACT (Action Chunking Transformer) model inference and session management capabilities.

## Features

- βœ… **Fully Generated**: Client is 100% generated from OpenAPI spec
- πŸ”’ **Type Safe**: Complete TypeScript support with generated types
- πŸš€ **Modern**: Built with Bun and modern JavaScript features
- πŸ“¦ **Lightweight**: Minimal dependencies, uses fetch API
- πŸ› οΈ **Developer Friendly**: Comprehensive examples and documentation

## Installation

```bash
# Install dependencies
bun install

# Generate client from OpenAPI spec
bun run generate

# Build the client
bun run build
```

## Quick Start

```typescript
import { RobotHubInferenceClient, CreateSessionRequest } from '@robothub/inference-server-client';

// Create client
const client = new RobotHubInferenceClient('http://localhost:8001');

// Check server health
const isHealthy = await client.isHealthy();
if (!isHealthy) {
  console.error('Server is not available');
  process.exit(1);
}

// Create and start a session
const sessionRequest: CreateSessionRequest = {
  session_id: 'my-robot-session',
  policy_path: 'LaetusH/act_so101_beyond',
  camera_names: ['front', 'wrist'],
  transport_server_url: 'http://localhost:8000'
};

const session = await client.createSession(sessionRequest);
await client.startInference('my-robot-session');

// Monitor session
const status = await client.getSessionStatus('my-robot-session');
console.log(`Status: ${status.status}`);

// Clean up
await client.deleteSession('my-robot-session');
```

## API Reference

### Client Creation

```typescript
const client = new RobotHubInferenceClient(baseUrl: string);
```

### Health Check Methods

- `isHealthy()`: Quick boolean health check
- `getHealth()`: Detailed health information

### Session Management

- `createSession(request: CreateSessionRequest)`: Create inference session
- `listSessions()`: List all active sessions
- `getSessionStatus(sessionId: string)`: Get session details
- `deleteSession(sessionId: string)`: Delete session and cleanup

### Inference Control

- `startInference(sessionId: string)`: Start model inference
- `stopInference(sessionId: string)`: Stop model inference  
- `restartInference(sessionId: string)`: Restart model inference

### Utility Methods

- `waitForSessionStatus(sessionId, targetStatus, timeout)`: Wait for status change
- `createAndStartSession(request)`: Create session and start inference in one call

### Debug Methods

- `getSystemInfo()`: Get server system information
- `debugResetSession(sessionId: string)`: Reset session state
- `getSessionQueueInfo(sessionId: string)`: Get action queue details

## Generated Types

All types are generated from the OpenAPI specification:

```typescript
import type { 
  CreateSessionRequest,
  CreateSessionResponse,
  SessionStatusResponse,
  // ... all other types
} from '@robothub/inference-server-client';
```

Key types:
- `CreateSessionRequest`: Session creation parameters
- `CreateSessionResponse`: Session creation result with room IDs
- `SessionStatusResponse`: Complete session status and statistics

## Examples

### Basic Usage
```bash
bun run examples/basic-usage.ts
```

### Quick Example  
```bash
bun run examples/basic-usage.ts --quick
```

## Development

### Scripts

- `bun run generate`: Export OpenAPI schema and generate client
- `bun run build`: Build the client distribution
- `bun run typecheck`: Run TypeScript type checking
- `bun run test`: Run tests
- `bun run clean`: Clean generated files and dist

### Regenerating Client

The client is automatically regenerated when you run `bun run build`. To manually regenerate:

```bash
# Export latest OpenAPI schema from inference server
bun run export-openapi

# Generate TypeScript client from schema
bun run generate-client
```

### File Structure

```
client/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ generated/          # Auto-generated from OpenAPI
β”‚   β”‚   β”œβ”€β”€ index.ts        # Generated exports
β”‚   β”‚   β”œβ”€β”€ services.gen.ts # Generated API methods
β”‚   β”‚   β”œβ”€β”€ types.gen.ts    # Generated TypeScript types
β”‚   β”‚   └── schemas.gen.ts  # Generated schemas
β”‚   └── index.ts            # Main client wrapper
β”œβ”€β”€ examples/
β”‚   └── basic-usage.ts      # Usage examples
β”œβ”€β”€ dist/                   # Built files
β”œβ”€β”€ openapi.json           # Latest OpenAPI schema
└── package.json
```

## Requirements

- **Bun** >= 1.0.0 (for development and building)
- **RobotHub Inference Server** running on target URL
- **RobotHub Transport Server** for communication rooms

## Communication Architecture

The inference server uses the RobotHub communication system:

1. **Camera Rooms**: Receive video streams (supports multiple cameras)
2. **Joint Input Room**: Receives current robot joint positions (normalized -100 to +100)
3. **Joint Output Room**: Sends predicted joint commands (normalized -100 to +100)

All rooms are created in the same workspace for session isolation.

## Error Handling

All client methods throw descriptive errors on failure:

```typescript
try {
  await client.createSession(request);
} catch (error) {
  console.error('Session creation failed:', error.message);
}
```

## Contributing

This client is auto-generated from the OpenAPI specification. To make changes:

1. Update the inference server's FastAPI endpoints
2. Regenerate the client: `bun run generate`
3. Update examples and documentation as needed

## License

Apache 2.0 - See LICENSE file for details.