|
| 1 | +# EVI Proxy |
| 2 | + |
| 3 | +This example contains an EVI "proxy" that accepts a websocket connection from a client, connects to EVI, and forwards messages back and forth between the client and EVI. |
| 4 | + |
| 5 | +This app is useful as an example in its own right: it demonstrates |
| 6 | + * how to connect to EVI from a Typescript backend, |
| 7 | + * how to accept websocket connections, process messages, and send them upstream to EVI |
| 8 | + |
| 9 | +See [upstream.ts](app/upstream.ts) and [downstream.ts](app/downstream.ts) for more details. |
| 10 | + |
| 11 | +It is also useful as a debugging tool: it supports |
| 12 | + * recording and replaying EVI conversations, |
| 13 | + * simulating error conditions that you might want to handle to make your EVI application more robust. |
| 14 | + |
| 15 | +## Prerequisites |
| 16 | + |
| 17 | + - Node.js (for running the proxy and building the web frontend) |
| 18 | + - Hume AI API credentials |
| 19 | + |
| 20 | +## Installation |
| 21 | + |
| 22 | +1. Clone this repository: |
| 23 | + ```bash |
| 24 | + git clone <repository-url> |
| 25 | + cd eviproxy |
| 26 | + ``` |
| 27 | + |
| 28 | +2. Install dependencies for both app and web components: |
| 29 | + ```bash |
| 30 | + cd app && npm install |
| 31 | + cd ../web && npm install && npm run build |
| 32 | + cd .. |
| 33 | + ``` |
| 34 | + |
| 35 | +## Environment Variables |
| 36 | + |
| 37 | +Create a `.env` file in the `app/` directory with the following variables: |
| 38 | + |
| 39 | +```bash |
| 40 | +HUME_API_KEY=your_hume_api_key_here |
| 41 | +HUME_CONFIG_ID=your_config_id_here # Optional |
| 42 | +``` |
| 43 | + |
| 44 | +To get your API key: |
| 45 | +1. Log into the [Hume AI Platform](https://platform.hume.ai/) |
| 46 | +2. Visit the [API keys page](https://platform.hume.ai/settings/keys) |
| 47 | +3. See the [documentation](https://dev.hume.ai/docs/introduction/api-key) for detailed instructions |
| 48 | + |
| 49 | +## Usage |
| 50 | + |
| 51 | +### Start the Proxy Server |
| 52 | + |
| 53 | +```bash |
| 54 | +cd app && npm start |
| 55 | +``` |
| 56 | + |
| 57 | +This starts the WebSocket proxy server on port 3000 with an interactive CLI interface. The CLI allows you to: |
| 58 | +- Switch between record and playback modes |
| 59 | +- Control recording sessions |
| 60 | +- Manage saved conversation scripts |
| 61 | + |
| 62 | +### Connect Your Own Applications |
| 63 | + |
| 64 | +To connect your own Hume EVI applications to this proxy instead of directly to Hume's servers, configure them to use `http://localhost:3000` as the environment: |
| 65 | + |
| 66 | +**TypeScript/JavaScript:** |
| 67 | +```typescript |
| 68 | +const hume = new HumeClient({ |
| 69 | + environment: "http://localhost:3000" |
| 70 | +}); |
| 71 | +``` |
| 72 | + |
| 73 | +**Python:** |
| 74 | +```python |
| 75 | +client = AsyncHumeClient( |
| 76 | + environment="http://localhost:3000", |
| 77 | +) |
| 78 | +``` |
| 79 | + |
| 80 | +### Access the Web Interface |
| 81 | + |
| 82 | +The proxy also includes a built-in web interface available at: |
| 83 | +``` |
| 84 | +http://localhost:3000 |
| 85 | +``` |
| 86 | +The interface is built using [Vite](https://vitejs.dev). If you modify any |
| 87 | +frontend code, run `npm run build` in the `web/` directory again to rebuild the |
| 88 | +static assets. |
| 89 | + |
| 90 | +### Recording and Playback |
| 91 | + |
| 92 | +1. **Record Mode**: Captures real conversations with Hume EVI and saves them to JSONL files |
| 93 | +2. **Playback Mode**: Replays saved conversations for testing and debugging |
| 94 | +3. **Script Files**: Conversations are saved in JSONL format (default: `script.jsonl`) |
| 95 | + |
| 96 | +## Project Structure |
| 97 | + |
| 98 | +``` |
| 99 | +eviproxy/ |
| 100 | +├── app/ # Main proxy server (Node.js) |
| 101 | +│ ├── main.ts # Entry point and state machine |
| 102 | +│ ├── cli.ts # Interactive CLI interface |
| 103 | +│ ├── upstream.ts # Hume API connections |
| 104 | +│ ├── downstream.ts # Client WebSocket server |
| 105 | +│ ├── api.ts # HTTP API endpoints for web-based control |
| 106 | +│ └── util.ts # Helpers |
| 107 | +├── web/ # React frontend |
| 108 | +│ ├── app.tsx # Main React application entry point |
| 109 | +│ ├── EVIChat.tsx # Main chat interface using @humeai/voice-react |
| 110 | +│ ├── ChatControls.tsx # Voice controls (mute, stop, etc.) |
| 111 | +│ ├── ChatMessages.tsx # Message display component |
| 112 | +│ ├── StartCall.tsx # Call initiation component |
| 113 | +│ ├── WebSocketControls.tsx # WebSocket connection controls |
| 114 | +│ ├── index.html # HTML entry point |
| 115 | +│ └── package.json # Frontend dependencies |
| 116 | +└── shared/ # Shared TypeScript types |
| 117 | + └── types.ts # Common interfaces and types |
| 118 | +``` |
0 commit comments