Skip to content

Commit 47ae799

Browse files
authored
Merge pull request #7 from All-Hands-AI/add-react-vite-example
Add React Vite example app with TypeScript SDK integration
2 parents 8667b9b + 431a909 commit 47ae799

File tree

16 files changed

+3929
-5
lines changed

16 files changed

+3929
-5
lines changed
File renamed without changes.

.openhands/microagents/repo.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,17 @@ This client is intended for developers who want to:
8080
- Integrate OpenHands capabilities into existing TypeScript/JavaScript applications
8181
- Develop custom frontends for the OpenHands Agent Server
8282

83-
The client abstracts away the complexity of HTTP requests, WebSocket management, and API authentication, providing a clean, type-safe interface for all OpenHands Agent Server functionality.
83+
The client abstracts away the complexity of HTTP requests, WebSocket management, and API authentication, providing a clean, type-safe interface for all OpenHands Agent Server functionality.
84+
85+
## Example Application
86+
87+
The `example/` directory contains a React application built with Vite that demonstrates how to integrate the TypeScript SDK into a modern web application. This example serves as both a reference implementation and a verification tool to ensure the SDK works correctly in browser environments.
88+
89+
The example application showcases:
90+
- Proper SDK integration with ES module compatibility
91+
- TypeScript configuration for client-side development
92+
- Build processes that compile the SDK before running the application
93+
- Import verification of all major SDK classes and enums
94+
- Modern React development patterns with Vite tooling
95+
96+
This provides developers with a working template for building their own applications using the OpenHands Agent Server TypeScript Client.

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)