|
| 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 |
0 commit comments