Skip to content

Commit bc7afbd

Browse files
Add React Vite example app with TypeScript SDK integration
- Create example/ directory with complete Vite React TypeScript app - Configure SDK to output ES modules for browser compatibility - Add build script that builds SDK before starting the app - Implement hello world React component that imports and displays SDK functionality - Demonstrate successful integration of RemoteConversation, RemoteWorkspace, HttpClient classes - Show AgentExecutionStatus and EventSortOrder enum values - Include comprehensive README with setup and usage instructions - Configure Vite for CORS and external host access - Add TypeScript configuration with proper module resolution Co-authored-by: openhands <openhands@all-hands.dev>
1 parent 8667b9b commit bc7afbd

File tree

13 files changed

+3912
-1
lines changed

13 files changed

+3912
-1
lines changed

example/README.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# OpenHands SDK React Example
2+
3+
This is a basic React application built with Vite that demonstrates successful integration with the OpenHands Agent Server TypeScript Client SDK.
4+
5+
## Features
6+
7+
-**Local SDK Integration**: Uses a locally built version of the SDK via file dependency
8+
-**Automatic Build**: Builds the SDK before starting the app
9+
-**TypeScript Support**: Full TypeScript integration with type safety
10+
-**Import Verification**: Displays all imported SDK classes and enums
11+
-**Real-time Status**: Shows SDK import status and available functionality
12+
13+
## What's Demonstrated
14+
15+
The app successfully imports and displays:
16+
17+
### Main Classes
18+
- `RemoteConversation` - Main conversation management class
19+
- `RemoteWorkspace` - Workspace file operations class
20+
- `HttpClient` - HTTP client for API communication
21+
- `AgentExecutionStatus` - Enum for agent execution states
22+
- `EventSortOrder` - Enum for event sorting options
23+
24+
### Enum Values
25+
- **AgentExecutionStatus**: IDLE, RUNNING, PAUSED, FINISHED, ERROR
26+
- **EventSortOrder**: TIMESTAMP, REVERSE_TIMESTAMP
27+
28+
## Getting Started
29+
30+
### Prerequisites
31+
- Node.js (v18 or higher)
32+
- npm
33+
34+
### Installation & Running
35+
36+
1. **Install dependencies**:
37+
```bash
38+
npm install
39+
```
40+
41+
2. **Start development server**:
42+
```bash
43+
npm run dev
44+
```
45+
This will:
46+
- Build the SDK from `../agent-server-typescript-client`
47+
- Start the Vite dev server on port 12000
48+
- Open the app at `http://localhost:12000`
49+
50+
3. **Build for production**:
51+
```bash
52+
npm run build
53+
```
54+
55+
## Project Structure
56+
57+
```
58+
example/
59+
├── src/
60+
│ ├── App.tsx # Main React component with SDK integration
61+
│ ├── App.css # Styling
62+
│ ├── main.tsx # React entry point
63+
│ └── index.css # Global styles
64+
├── package.json # Dependencies and scripts
65+
├── vite.config.ts # Vite configuration
66+
├── tsconfig.json # TypeScript configuration
67+
└── index.html # HTML template
68+
```
69+
70+
## Key Configuration
71+
72+
### package.json
73+
- **Local SDK Dependency**: `"@openhands/agent-server-typescript-client": "file:../agent-server-typescript-client"`
74+
- **Build Script**: `"build:sdk": "cd ../agent-server-typescript-client && npm run build"`
75+
- **Dev Script**: Builds SDK before starting Vite
76+
77+
### vite.config.ts
78+
- Configured for React with TypeScript
79+
- CORS enabled for development
80+
- Host configuration for external access
81+
82+
## SDK Integration Details
83+
84+
The app demonstrates that the TypeScript SDK is properly:
85+
1. **Built as ES Modules** - Compatible with Vite's module system
86+
2. **Type-safe** - Full TypeScript support with proper type definitions
87+
3. **Functional** - All main classes and enums are importable and usable
88+
4. **Up-to-date** - Uses the latest local build of the SDK
89+
90+
## Notes
91+
92+
- The SDK includes some Node.js-specific functionality (fs, path modules) that are externalized for browser compatibility
93+
- This is expected behavior and doesn't affect the core SDK functionality in browser environments
94+
- The app serves as a "Hello World" example to verify SDK integration works correctly

example/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>OpenHands SDK Example</title>
8+
</head>
9+
<body>
10+
<div id="root"></div>
11+
<script type="module" src="/src/main.tsx"></script>
12+
</body>
13+
</html>

0 commit comments

Comments
 (0)