Building on MentraOS: SDK and Apps
Third-party apps are what make MentraOS magical. They extend the glasses’ capabilities from simple translation to AI assistants, note-taking, navigation, and more. Let’s see how apps connect and interact with the system.The MentraOS SDK
The SDK (@mentraos/sdk) is a TypeScript/JavaScript library that makes it easy for developers to build apps. Think of it as the translator between apps and our cloud.
Installation
How Apps Connect
Let’s follow a translator app as it connects to help Alex:Step 1: App Receives Start Signal
When Alex says “Start translator”, the cloud sends a webhook to the app:Step 2: App Creates Session
Step 3: Authentication Dance
The app sends its credentials:Step 4: Subscribe to Data Streams
Apps must tell the cloud what data they want:The AppSession Class
The SDK’s main class that handles everything:Working with Display Layouts
The SDK provides layout methods throughsession.layouts (defined in packages/sdk/src/app/session/modules/layouts.ts):
Receiving Events
Apps receive events through thesession.events object (defined in packages/sdk/src/app/session/index.ts):
Managing Settings
Apps can have user-configurable settings throughsession.settings (defined in packages/sdk/src/app/session/modules/settings.ts):
Hardware Modules
Camera Module
Camera functionality throughsession.camera (defined in packages/sdk/src/app/session/modules/camera.ts):
Audio Module
Audio functionality throughsession.audio (defined in packages/sdk/src/app/session/modules/audio.ts):
Location Module
Location functionality throughsession.location (defined in packages/sdk/src/app/session/modules/location.ts):
Dashboard Module
Dashboard control throughsession.dashboard (defined in packages/sdk/src/app/session/modules/dashboard.ts):
App Lifecycle
Starting Up
- Receive webhook with sessionId
- Create AppSession instance
- Connect to cloud
- Subscribe to needed events
- Show initial UI
Running
- Receive events from subscriptions
- Process data
- Update display as needed
- Respond to user actions
Shutting Down
- Receive ‘appStopped’ event
- Clean up resources
- Close connections
- App can be restarted later
Best Practices
1. Handle Disconnections Gracefully
2. Respect Rate Limits
3. Clean Up Resources
4. Use TypeScript
The SDK has full TypeScript support:Common App Patterns
Voice Command App
Real-time Information App
Interactive App
Multi-User Communication App
The SDK supports app-to-app communication (defined inpackages/sdk/src/app/session/app-to-app.ts):