@mentra/sdk 2.0.1 โ 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/app/server/index.d.ts +8 -8
- package/dist/app/server/index.d.ts.map +1 -1
- package/dist/app/server/index.js +9 -9
- package/dist/app/session/api-client.d.ts +3 -3
- package/dist/app/session/api-client.js +3 -3
- package/dist/app/session/index.d.ts +14 -9
- package/dist/app/session/index.d.ts.map +1 -1
- package/dist/app/session/index.js +46 -41
- package/dist/app/session/layouts.d.ts +1 -1
- package/dist/app/session/layouts.js +1 -1
- package/dist/app/session/settings.d.ts +25 -25
- package/dist/app/session/settings.d.ts.map +1 -1
- package/dist/app/session/settings.js +46 -46
- package/dist/app/webview/index.d.ts +3 -3
- package/dist/app/webview/index.js +4 -4
- package/dist/examples/rtmp-streaming-example.js +3 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/message-types.d.ts +2 -2
- package/dist/types/message-types.d.ts.map +1 -1
- package/dist/types/message-types.js +2 -2
- package/dist/types/messages/cloud-to-app.d.ts +4 -4
- package/dist/types/messages/cloud-to-app.d.ts.map +1 -1
- package/dist/types/messages/glasses-to-cloud.d.ts +4 -4
- package/dist/types/messages/glasses-to-cloud.d.ts.map +1 -1
- package/dist/types/streams.d.ts +1 -1
- package/dist/types/streams.d.ts.map +1 -1
- package/dist/types/streams.js +2 -2
- package/dist/types/token.d.ts +1 -1
- package/dist/types/token.d.ts.map +1 -1
- package/dist/types/webhooks.d.ts +2 -1
- package/dist/types/webhooks.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
@@ -74,7 +74,7 @@ We are going to use ngrok to expose your local app to the internet. This is usef
|
|
74
74
|
```
|
75
75
|
PORT=3000
|
76
76
|
PACKAGE_NAME=com.yourName.yourAppName
|
77
|
-
|
77
|
+
MENTRAOS_API_KEY=your_api_key_from_console
|
78
78
|
```
|
79
79
|
* Make sure the `PACKAGE_NAME` matches what you registered in the MentraOS Console
|
80
80
|
* Get your `API_KEY` from the MentraOS Developer Console
|
@@ -1,7 +1,7 @@
|
|
1
1
|
/**
|
2
2
|
* ๐ App Server Module
|
3
3
|
*
|
4
|
-
* Creates and manages a server for Third Party Apps (Apps) in the
|
4
|
+
* Creates and manages a server for Third Party Apps (Apps) in the MentraOS ecosystem.
|
5
5
|
* Handles webhook endpoints, session management, and cleanup.
|
6
6
|
*/
|
7
7
|
import { type Express } from 'express';
|
@@ -24,7 +24,7 @@ import { Logger } from 'pino';
|
|
24
24
|
export interface AppServerConfig {
|
25
25
|
/** ๐ฆ Unique identifier for your App (e.g., 'org.company.appname') must match what you specified at https://console.mentra.glass */
|
26
26
|
packageName: string;
|
27
|
-
/** ๐ API key for authentication with
|
27
|
+
/** ๐ API key for authentication with MentraOS Cloud */
|
28
28
|
apiKey: string;
|
29
29
|
/** ๐ Port number for the server (default: 7010) */
|
30
30
|
port?: number;
|
@@ -50,7 +50,7 @@ export interface AppServerConfig {
|
|
50
50
|
*
|
51
51
|
* Base class for creating App servers. Handles:
|
52
52
|
* - ๐ Session lifecycle management
|
53
|
-
* - ๐ก Webhook endpoints for
|
53
|
+
* - ๐ก Webhook endpoints for MentraOS Cloud
|
54
54
|
* - ๐ Static file serving
|
55
55
|
* - โค๏ธ Health checks
|
56
56
|
* - ๐งน Cleanup on shutdown
|
@@ -110,11 +110,11 @@ export declare class AppServer {
|
|
110
110
|
protected onStop(sessionId: string, userId: string, reason: string): Promise<void>;
|
111
111
|
/**
|
112
112
|
* ๐ ๏ธ Tool Call Handler
|
113
|
-
* Override this method to handle tool calls from
|
113
|
+
* Override this method to handle tool calls from MentraOS Cloud.
|
114
114
|
* This is where you implement your app's tool functionality.
|
115
115
|
*
|
116
116
|
* @param toolCall - The tool call request containing tool details and parameters
|
117
|
-
* @returns Optional string response that will be sent back to
|
117
|
+
* @returns Optional string response that will be sent back to MentraOS Cloud
|
118
118
|
*/
|
119
119
|
protected onToolCall(toolCall: ToolCall): Promise<string | undefined>;
|
120
120
|
/**
|
@@ -148,12 +148,12 @@ export declare class AppServer {
|
|
148
148
|
protected addCleanupHandler(handler: () => void): void;
|
149
149
|
/**
|
150
150
|
* ๐ฏ Setup Webhook Endpoint
|
151
|
-
* Creates the webhook endpoint that
|
151
|
+
* Creates the webhook endpoint that MentraOS Cloud calls to start new sessions.
|
152
152
|
*/
|
153
153
|
private setupWebhook;
|
154
154
|
/**
|
155
155
|
* ๐ ๏ธ Setup Tool Call Endpoint
|
156
|
-
* Creates a /tool endpoint for handling tool calls from
|
156
|
+
* Creates a /tool endpoint for handling tool calls from MentraOS Cloud.
|
157
157
|
*/
|
158
158
|
private setupToolCallEndpoint;
|
159
159
|
/**
|
@@ -171,7 +171,7 @@ export declare class AppServer {
|
|
171
171
|
private setupHealthCheck;
|
172
172
|
/**
|
173
173
|
* โ๏ธ Setup Settings Endpoint
|
174
|
-
* Creates a /settings endpoint that the
|
174
|
+
* Creates a /settings endpoint that the MentraOS Cloud can use to update settings.
|
175
175
|
*/
|
176
176
|
private setupSettingsEndpoint;
|
177
177
|
/**
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/app/server/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAgB,EAAE,KAAK,OAAO,EAAE,MAAM,SAAS,CAAC;AAEhD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EAQL,QAAQ,EACT,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAI9B;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,eAAe;IAC9B,oIAAoI;IACpI,WAAW,EAAE,MAAM,CAAC;IACpB,
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/app/server/index.ts"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SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAWxF;;;;;;;OAOG;cACa,UAAU,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAM3E;;;;;OAKG;IACI,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAY7B;;;OAGG;IACI,IAAI,IAAI,IAAI;IAMnB;;;;;;;;KAQC;IACD,SAAS,CAAC,aAAa,CACrB,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAChB,MAAM;IAYT;;;;;OAKG;IACH,SAAS,CAAC,iBAAiB,CAAC,OAAO,EAAE,MAAM,IAAI,GAAG,IAAI;IAItD;;;OAGG;IACH,OAAO,CAAC,YAAY;IAoCpB;;;OAGG;IACH,OAAO,CAAC,qBAAqB;IA2B7B;;OAEG;YACW,oBAAoB;IA6DlC;;OAEG;YACW,iBAAiB;IAgB/B;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IAYxB;;;OAGG;IACH,OAAO,CAAC,qBAAqB;IAyD7B;;;OAGG;IACH,OAAO,CAAC,cAAc;IAQtB;;;OAGG;IACH,OAAO,CAAC,aAAa;IAKrB;;;OAGG;IACH,OAAO,CAAC,OAAO;CAWhB"}
|
package/dist/app/server/index.js
CHANGED
@@ -7,7 +7,7 @@ exports.AppServer = void 0;
|
|
7
7
|
/**
|
8
8
|
* ๐ App Server Module
|
9
9
|
*
|
10
|
-
* Creates and manages a server for Third Party Apps (Apps) in the
|
10
|
+
* Creates and manages a server for Third Party Apps (Apps) in the MentraOS ecosystem.
|
11
11
|
* Handles webhook endpoints, session management, and cleanup.
|
12
12
|
*/
|
13
13
|
const express_1 = __importDefault(require("express"));
|
@@ -21,7 +21,7 @@ const logger_1 = require("../../logging/logger");
|
|
21
21
|
*
|
22
22
|
* Base class for creating App servers. Handles:
|
23
23
|
* - ๐ Session lifecycle management
|
24
|
-
* - ๐ก Webhook endpoints for
|
24
|
+
* - ๐ก Webhook endpoints for MentraOS Cloud
|
25
25
|
* - ๐ Static file serving
|
26
26
|
* - โค๏ธ Health checks
|
27
27
|
* - ๐งน Cleanup on shutdown
|
@@ -123,11 +123,11 @@ class AppServer {
|
|
123
123
|
}
|
124
124
|
/**
|
125
125
|
* ๐ ๏ธ Tool Call Handler
|
126
|
-
* Override this method to handle tool calls from
|
126
|
+
* Override this method to handle tool calls from MentraOS Cloud.
|
127
127
|
* This is where you implement your app's tool functionality.
|
128
128
|
*
|
129
129
|
* @param toolCall - The tool call request containing tool details and parameters
|
130
|
-
* @returns Optional string response that will be sent back to
|
130
|
+
* @returns Optional string response that will be sent back to MentraOS Cloud
|
131
131
|
*/
|
132
132
|
async onToolCall(toolCall) {
|
133
133
|
this.logger.debug(`Tool call received: ${toolCall.toolId}`);
|
@@ -188,7 +188,7 @@ class AppServer {
|
|
188
188
|
}
|
189
189
|
/**
|
190
190
|
* ๐ฏ Setup Webhook Endpoint
|
191
|
-
* Creates the webhook endpoint that
|
191
|
+
* Creates the webhook endpoint that MentraOS Cloud calls to start new sessions.
|
192
192
|
*/
|
193
193
|
setupWebhook() {
|
194
194
|
if (!this.config.webhookPath) {
|
@@ -226,7 +226,7 @@ class AppServer {
|
|
226
226
|
}
|
227
227
|
/**
|
228
228
|
* ๐ ๏ธ Setup Tool Call Endpoint
|
229
|
-
* Creates a /tool endpoint for handling tool calls from
|
229
|
+
* Creates a /tool endpoint for handling tool calls from MentraOS Cloud.
|
230
230
|
*/
|
231
231
|
setupToolCallEndpoint() {
|
232
232
|
this.app.post('/tool', async (req, res) => {
|
@@ -259,13 +259,13 @@ class AppServer {
|
|
259
259
|
* Handle a session request webhook
|
260
260
|
*/
|
261
261
|
async handleSessionRequest(request, res) {
|
262
|
-
const { sessionId, userId, augmentOSWebsocketUrl } = request;
|
262
|
+
const { sessionId, userId, mentraOSWebsocketUrl, augmentOSWebsocketUrl } = request;
|
263
263
|
this.logger.info({ userId }, `๐ฃ๏ธ Received session request for user ${userId}, session ${sessionId}\n\n`);
|
264
264
|
// Create new App session
|
265
265
|
const session = new index_1.AppSession({
|
266
266
|
packageName: this.config.packageName,
|
267
267
|
apiKey: this.config.apiKey,
|
268
|
-
augmentOSWebsocketUrl, // The websocket URL for the specific
|
268
|
+
mentraOSWebsocketUrl: mentraOSWebsocketUrl || augmentOSWebsocketUrl, // The websocket URL for the specific MentraOS server that this userSession is connecting to.
|
269
269
|
appServer: this,
|
270
270
|
userId,
|
271
271
|
});
|
@@ -347,7 +347,7 @@ class AppServer {
|
|
347
347
|
}
|
348
348
|
/**
|
349
349
|
* โ๏ธ Setup Settings Endpoint
|
350
|
-
* Creates a /settings endpoint that the
|
350
|
+
* Creates a /settings endpoint that the MentraOS Cloud can use to update settings.
|
351
351
|
*/
|
352
352
|
setupSettingsEndpoint() {
|
353
353
|
this.app.post('/settings', async (req, res) => {
|
@@ -1,7 +1,7 @@
|
|
1
1
|
/**
|
2
2
|
* ๐ API Client Module
|
3
3
|
*
|
4
|
-
* Provides HTTP API access to
|
4
|
+
* Provides HTTP API access to MentraOS Cloud services.
|
5
5
|
* Automatically uses the correct server URL derived from the WebSocket URL.
|
6
6
|
*/
|
7
7
|
/**
|
@@ -12,7 +12,7 @@
|
|
12
12
|
*/
|
13
13
|
export declare function wsUrlToHttpUrl(wsUrl?: string): string | undefined;
|
14
14
|
/**
|
15
|
-
* API client class for making HTTP requests to
|
15
|
+
* API client class for making HTTP requests to MentraOS Cloud
|
16
16
|
*/
|
17
17
|
export declare class ApiClient {
|
18
18
|
private baseUrl;
|
@@ -39,7 +39,7 @@ export declare class ApiClient {
|
|
39
39
|
*/
|
40
40
|
setUserId(userId: string): void;
|
41
41
|
/**
|
42
|
-
* Fetch settings from
|
42
|
+
* Fetch settings from MentraOS Cloud
|
43
43
|
*
|
44
44
|
* @returns Promise resolving to settings array
|
45
45
|
* @throws Error if client is not configured correctly or if request fails
|
@@ -2,7 +2,7 @@
|
|
2
2
|
/**
|
3
3
|
* ๐ API Client Module
|
4
4
|
*
|
5
|
-
* Provides HTTP API access to
|
5
|
+
* Provides HTTP API access to MentraOS Cloud services.
|
6
6
|
* Automatically uses the correct server URL derived from the WebSocket URL.
|
7
7
|
*/
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
@@ -31,7 +31,7 @@ function wsUrlToHttpUrl(wsUrl) {
|
|
31
31
|
}
|
32
32
|
}
|
33
33
|
/**
|
34
|
-
* API client class for making HTTP requests to
|
34
|
+
* API client class for making HTTP requests to MentraOS Cloud
|
35
35
|
*/
|
36
36
|
class ApiClient {
|
37
37
|
/**
|
@@ -65,7 +65,7 @@ class ApiClient {
|
|
65
65
|
this.userId = userId;
|
66
66
|
}
|
67
67
|
/**
|
68
|
-
* Fetch settings from
|
68
|
+
* Fetch settings from MentraOS Cloud
|
69
69
|
*
|
70
70
|
* @returns Promise resolving to settings array
|
71
71
|
* @throws Error if client is not configured correctly or if request fails
|
@@ -22,10 +22,10 @@ import { AppServer } from '../server';
|
|
22
22
|
export interface AppSessionConfig {
|
23
23
|
/** ๐ฆ Unique identifier for your App (e.g., 'org.company.appname') */
|
24
24
|
packageName: string;
|
25
|
-
/** ๐ API key for authentication with
|
25
|
+
/** ๐ API key for authentication with MentraOS Cloud */
|
26
26
|
apiKey: string;
|
27
27
|
/** ๐ WebSocket server URL (default: 'ws://localhost:7002/app-ws') */
|
28
|
-
|
28
|
+
mentraOSWebsocketUrl?: string;
|
29
29
|
/** ๐ Automatically attempt to reconnect on disconnect (default: true) */
|
30
30
|
autoReconnect?: boolean;
|
31
31
|
/** ๐ Maximum number of reconnection attempts (default: 3) */
|
@@ -38,7 +38,7 @@ export interface AppSessionConfig {
|
|
38
38
|
/**
|
39
39
|
* ๐ App Session Implementation
|
40
40
|
*
|
41
|
-
* Manages a live connection between your App and
|
41
|
+
* Manages a live connection between your App and MentraOS Cloud.
|
42
42
|
* Provides interfaces for:
|
43
43
|
* - ๐ฎ Event handling (transcription, head position, etc.)
|
44
44
|
* - ๐ฑ Display management in AR view
|
@@ -63,7 +63,7 @@ export interface AppSessionConfig {
|
|
63
63
|
*/
|
64
64
|
export declare class AppSession {
|
65
65
|
private config;
|
66
|
-
/** WebSocket connection to
|
66
|
+
/** WebSocket connection to MentraOS Cloud */
|
67
67
|
private ws;
|
68
68
|
/** Current session identifier */
|
69
69
|
private sessionId;
|
@@ -118,9 +118,7 @@ export declare class AppSession {
|
|
118
118
|
*/
|
119
119
|
getPackageName(): string;
|
120
120
|
/**
|
121
|
-
*
|
122
|
-
* @param handler - Function to handle transcription data
|
123
|
-
* @returns Cleanup function to remove the handler
|
121
|
+
* @deprecated Use session.events.onTranscription() instead
|
124
122
|
*/
|
125
123
|
onTranscription(handler: (data: TranscriptionData) => void): () => void;
|
126
124
|
/**
|
@@ -129,6 +127,7 @@ export declare class AppSession {
|
|
129
127
|
* @param handler - Function to handle transcription data
|
130
128
|
* @returns Cleanup function to remove the handler
|
131
129
|
* @throws Error if language code is invalid
|
130
|
+
* @deprecated Use session.events.onTranscriptionForLanguage() instead
|
132
131
|
*/
|
133
132
|
onTranscriptionForLanguage(language: string, handler: (data: TranscriptionData) => void): () => void;
|
134
133
|
/**
|
@@ -138,36 +137,42 @@ export declare class AppSession {
|
|
138
137
|
* @param handler - Function to handle translation data
|
139
138
|
* @returns Cleanup function to remove the handler
|
140
139
|
* @throws Error if language codes are invalid
|
140
|
+
* @deprecated Use session.events.onTranslationForLanguage() instead
|
141
141
|
*/
|
142
142
|
onTranslationForLanguage(sourceLanguage: string, targetLanguage: string, handler: (data: TranslationData) => void): () => void;
|
143
143
|
/**
|
144
144
|
* ๐ค Listen for head position changes
|
145
145
|
* @param handler - Function to handle head position updates
|
146
146
|
* @returns Cleanup function to remove the handler
|
147
|
+
* @deprecated Use session.events.onHeadPosition() instead
|
147
148
|
*/
|
148
149
|
onHeadPosition(handler: (data: HeadPosition) => void): () => void;
|
149
150
|
/**
|
150
151
|
* ๐ Listen for hardware button press events
|
151
152
|
* @param handler - Function to handle button events
|
152
153
|
* @returns Cleanup function to remove the handler
|
154
|
+
* @deprecated Use session.events.onButtonPress() instead
|
153
155
|
*/
|
154
156
|
onButtonPress(handler: (data: ButtonPress) => void): () => void;
|
155
157
|
/**
|
156
158
|
* ๐ฑ Listen for phone notification events
|
157
159
|
* @param handler - Function to handle notifications
|
158
160
|
* @returns Cleanup function to remove the handler
|
161
|
+
* @deprecated Use session.events.onPhoneNotifications() instead
|
159
162
|
*/
|
160
163
|
onPhoneNotifications(handler: (data: PhoneNotification) => void): () => void;
|
161
164
|
/**
|
162
165
|
* ๐ก Listen for VPS coordinates updates
|
163
166
|
* @param handler - Function to handle VPS coordinates
|
164
167
|
* @returns Cleanup function to remove the handler
|
168
|
+
* @deprecated Use session.events.onVpsCoordinates() instead
|
165
169
|
*/
|
166
170
|
onVpsCoordinates(handler: (data: VpsCoordinates) => void): () => void;
|
167
171
|
/**
|
168
172
|
* ๐ธ Listen for photo responses
|
169
173
|
* @param handler - Function to handle photo response data
|
170
174
|
* @returns Cleanup function to remove the handler
|
175
|
+
* @deprecated Use session.events.onPhotoTaken() instead
|
171
176
|
*/
|
172
177
|
onPhotoTaken(handler: (data: PhotoTaken) => void): () => void;
|
173
178
|
/**
|
@@ -187,13 +192,13 @@ export declare class AppSession {
|
|
187
192
|
*/
|
188
193
|
on<T extends ExtendedStreamType>(event: T, handler: (data: EventData<T>) => void): () => void;
|
189
194
|
/**
|
190
|
-
* ๐ Connect to
|
195
|
+
* ๐ Connect to MentraOS Cloud
|
191
196
|
* @param sessionId - Unique session identifier
|
192
197
|
* @returns Promise that resolves when connected
|
193
198
|
*/
|
194
199
|
connect(sessionId: string): Promise<void>;
|
195
200
|
/**
|
196
|
-
* ๐ Disconnect from
|
201
|
+
* ๐ Disconnect from MentraOS Cloud
|
197
202
|
*/
|
198
203
|
disconnect(): void;
|
199
204
|
/**
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/app/session/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAmB,MAAM,UAAU,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,OAAO,EAYL,kBAAkB,EAClB,WAAW,EACX,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EAYf,WAAW,EACX,UAAU,EACV,SAAS,EAQT,cAAc,EACd,UAAU,EACV,YAAY,EACb,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAQtC;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,gBAAgB;IAC/B,sEAAsE;IACtE,WAAW,EAAE,MAAM,CAAC;IACpB,
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/app/session/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAmB,MAAM,UAAU,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,OAAO,EAYL,kBAAkB,EAClB,WAAW,EACX,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EAYf,WAAW,EACX,UAAU,EACV,SAAS,EAQT,cAAc,EACd,UAAU,EACV,YAAY,EACb,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;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G;IACG,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE;QAC7C,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,SAAS,CAAC,EAAE,OAAO,CAAC;QACpB,QAAQ,CAAC,EAAE,GAAG,CAAC;KAChB,GAAG,OAAO,CAAC,IAAI,CAAC;IAkBjB;;;;OAIG;IACG,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBjD;;;;OAIG;IACH,YAAY,CAAC,OAAO,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,IAAI,GAAG,MAAM,IAAI;IAKzD;;;;OAIG;IACH,eAAe,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,GAAG,MAAM,IAAI;IAKzD;;;;OAIG;IACH,aAAa,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,GAAG,MAAM,IAAI;IAKvD;;;;OAIG;IACH,gBAAgB,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,GAAG,MAAM,IAAI;IAK1D;;;OAGG;IACH,OAAO,CAAC,iBAAiB;CAG1B"}
|
@@ -7,7 +7,7 @@ exports.AppSession = void 0;
|
|
7
7
|
/**
|
8
8
|
* ๐ฏ App Session Module
|
9
9
|
*
|
10
|
-
* Manages an active Third Party App session with
|
10
|
+
* Manages an active Third Party App session with MentraOS Cloud.
|
11
11
|
* Handles real-time communication, event subscriptions, and display management.
|
12
12
|
*/
|
13
13
|
const ws_1 = require("ws");
|
@@ -32,7 +32,7 @@ const APP_TO_APP_EVENT_TYPES = [
|
|
32
32
|
/**
|
33
33
|
* ๐ App Session Implementation
|
34
34
|
*
|
35
|
-
* Manages a live connection between your App and
|
35
|
+
* Manages a live connection between your App and MentraOS Cloud.
|
36
36
|
* Provides interfaces for:
|
37
37
|
* - ๐ฎ Event handling (transcription, head position, etc.)
|
38
38
|
* - ๐ฑ Display management in AR view
|
@@ -58,7 +58,7 @@ const APP_TO_APP_EVENT_TYPES = [
|
|
58
58
|
class AppSession {
|
59
59
|
constructor(config) {
|
60
60
|
this.config = config;
|
61
|
-
/** WebSocket connection to
|
61
|
+
/** WebSocket connection to MentraOS Cloud */
|
62
62
|
this.ws = null;
|
63
63
|
/** Current session identifier */
|
64
64
|
this.sessionId = null;
|
@@ -88,7 +88,7 @@ class AppSession {
|
|
88
88
|
this.appEvents = new events_2.default();
|
89
89
|
// Set defaults and merge with provided config
|
90
90
|
this.config = {
|
91
|
-
|
91
|
+
mentraOSWebsocketUrl: `ws://localhost:8002/app-ws`, // Use localhost as default
|
92
92
|
autoReconnect: true, // Enable auto-reconnection by default for better reliability
|
93
93
|
maxReconnectAttempts: 3, // Default to 3 reconnection attempts for better resilience
|
94
94
|
reconnectDelay: 1000, // Start with 1 second delay (uses exponential backoff)
|
@@ -98,45 +98,45 @@ class AppSession {
|
|
98
98
|
this.logger = this.appServer.logger.child({ userId: this.config.userId, service: 'app-session' });
|
99
99
|
this.userId = this.config.userId;
|
100
100
|
// Make sure the URL is correctly formatted to prevent double protocol issues
|
101
|
-
if (this.config.
|
101
|
+
if (this.config.mentraOSWebsocketUrl) {
|
102
102
|
try {
|
103
|
-
const url = new URL(this.config.
|
103
|
+
const url = new URL(this.config.mentraOSWebsocketUrl);
|
104
104
|
if (!['ws:', 'wss:'].includes(url.protocol)) {
|
105
105
|
// Fix URLs with incorrect protocol (e.g., 'ws://http://host')
|
106
|
-
const fixedUrl = this.config.
|
107
|
-
this.config.
|
106
|
+
const fixedUrl = this.config.mentraOSWebsocketUrl.replace(/^ws:\/\/http:\/\//, 'ws://');
|
107
|
+
this.config.mentraOSWebsocketUrl = fixedUrl;
|
108
108
|
this.logger.warn(`โ ๏ธ [${this.config.packageName}] Fixed malformed WebSocket URL: ${fixedUrl}`);
|
109
109
|
}
|
110
110
|
}
|
111
111
|
catch (error) {
|
112
|
-
this.logger.error(error, `โ ๏ธ [${this.config.packageName}] Invalid WebSocket URL format: ${this.config.
|
112
|
+
this.logger.error(error, `โ ๏ธ [${this.config.packageName}] Invalid WebSocket URL format: ${this.config.mentraOSWebsocketUrl}`);
|
113
113
|
}
|
114
114
|
}
|
115
115
|
// Log initialization
|
116
116
|
this.logger.debug(`๐ [${this.config.packageName}] App Session initialized`);
|
117
|
-
this.logger.debug(`๐ [${this.config.packageName}] WebSocket URL: ${this.config.
|
117
|
+
this.logger.debug(`๐ [${this.config.packageName}] WebSocket URL: ${this.config.mentraOSWebsocketUrl}`);
|
118
118
|
// Validate URL format - give early warning for obvious issues
|
119
119
|
// Check URL format but handle undefined case
|
120
|
-
if (this.config.
|
120
|
+
if (this.config.mentraOSWebsocketUrl) {
|
121
121
|
try {
|
122
|
-
const url = new URL(this.config.
|
122
|
+
const url = new URL(this.config.mentraOSWebsocketUrl);
|
123
123
|
if (!['ws:', 'wss:'].includes(url.protocol)) {
|
124
124
|
this.logger.error({ config: this.config }, `โ ๏ธ [${this.config.packageName}] Invalid WebSocket URL protocol: ${url.protocol}. Should be ws: or wss:`);
|
125
125
|
}
|
126
126
|
}
|
127
127
|
catch (error) {
|
128
|
-
this.logger.error(error, `โ ๏ธ [${this.config.packageName}] Invalid WebSocket URL format: ${this.config.
|
128
|
+
this.logger.error(error, `โ ๏ธ [${this.config.packageName}] Invalid WebSocket URL format: ${this.config.mentraOSWebsocketUrl}`);
|
129
129
|
}
|
130
130
|
}
|
131
131
|
this.events = new events_1.EventManager(this.subscribe.bind(this), this.unsubscribe.bind(this));
|
132
132
|
this.layouts = new layouts_1.LayoutManager(config.packageName, this.send.bind(this));
|
133
|
-
// Initialize settings manager with all necessary parameters, including subscribeFn for
|
134
|
-
this.settings = new settings_1.SettingsManager(this.settingsData, this.config.packageName, this.config.
|
133
|
+
// Initialize settings manager with all necessary parameters, including subscribeFn for MentraOS settings
|
134
|
+
this.settings = new settings_1.SettingsManager(this.settingsData, this.config.packageName, this.config.mentraOSWebsocketUrl, this.sessionId ?? undefined, async (streams) => {
|
135
135
|
this.logger.debug(`[AppSession] subscribeFn called for streams:`, streams);
|
136
136
|
streams.forEach((stream) => {
|
137
137
|
if (!this.subscriptions.has(stream)) {
|
138
138
|
this.subscriptions.add(stream);
|
139
|
-
this.logger.debug(`[AppSession] Auto-subscribed to stream '${stream}' for
|
139
|
+
this.logger.debug(`[AppSession] Auto-subscribed to stream '${stream}' for MentraOS setting.`);
|
140
140
|
}
|
141
141
|
else {
|
142
142
|
this.logger.debug(`[AppSession] Already subscribed to stream '${stream}'.`);
|
@@ -145,7 +145,7 @@ class AppSession {
|
|
145
145
|
this.logger.debug(`[AppSession] Current subscriptions after subscribeFn:`, Array.from(this.subscriptions));
|
146
146
|
if (this.ws?.readyState === 1) {
|
147
147
|
this.updateSubscriptions();
|
148
|
-
this.logger.debug(`[AppSession] Sent updated subscriptions to cloud after auto-subscribing to
|
148
|
+
this.logger.debug(`[AppSession] Sent updated subscriptions to cloud after auto-subscribing to MentraOS setting.`);
|
149
149
|
}
|
150
150
|
else {
|
151
151
|
this.logger.debug(`[AppSession] WebSocket not open, will send subscriptions when connected.`);
|
@@ -177,9 +177,7 @@ class AppSession {
|
|
177
177
|
// ๐ฎ Direct Event Handling Interface
|
178
178
|
// =====================================
|
179
179
|
/**
|
180
|
-
*
|
181
|
-
* @param handler - Function to handle transcription data
|
182
|
-
* @returns Cleanup function to remove the handler
|
180
|
+
* @deprecated Use session.events.onTranscription() instead
|
183
181
|
*/
|
184
182
|
onTranscription(handler) {
|
185
183
|
return this.events.onTranscription(handler);
|
@@ -190,6 +188,7 @@ class AppSession {
|
|
190
188
|
* @param handler - Function to handle transcription data
|
191
189
|
* @returns Cleanup function to remove the handler
|
192
190
|
* @throws Error if language code is invalid
|
191
|
+
* @deprecated Use session.events.onTranscriptionForLanguage() instead
|
193
192
|
*/
|
194
193
|
onTranscriptionForLanguage(language, handler) {
|
195
194
|
return this.events.onTranscriptionForLanguage(language, handler);
|
@@ -201,6 +200,7 @@ class AppSession {
|
|
201
200
|
* @param handler - Function to handle translation data
|
202
201
|
* @returns Cleanup function to remove the handler
|
203
202
|
* @throws Error if language codes are invalid
|
203
|
+
* @deprecated Use session.events.onTranslationForLanguage() instead
|
204
204
|
*/
|
205
205
|
onTranslationForLanguage(sourceLanguage, targetLanguage, handler) {
|
206
206
|
return this.events.ontranslationForLanguage(sourceLanguage, targetLanguage, handler);
|
@@ -209,6 +209,7 @@ class AppSession {
|
|
209
209
|
* ๐ค Listen for head position changes
|
210
210
|
* @param handler - Function to handle head position updates
|
211
211
|
* @returns Cleanup function to remove the handler
|
212
|
+
* @deprecated Use session.events.onHeadPosition() instead
|
212
213
|
*/
|
213
214
|
onHeadPosition(handler) {
|
214
215
|
return this.events.onHeadPosition(handler);
|
@@ -217,6 +218,7 @@ class AppSession {
|
|
217
218
|
* ๐ Listen for hardware button press events
|
218
219
|
* @param handler - Function to handle button events
|
219
220
|
* @returns Cleanup function to remove the handler
|
221
|
+
* @deprecated Use session.events.onButtonPress() instead
|
220
222
|
*/
|
221
223
|
onButtonPress(handler) {
|
222
224
|
return this.events.onButtonPress(handler);
|
@@ -225,6 +227,7 @@ class AppSession {
|
|
225
227
|
* ๐ฑ Listen for phone notification events
|
226
228
|
* @param handler - Function to handle notifications
|
227
229
|
* @returns Cleanup function to remove the handler
|
230
|
+
* @deprecated Use session.events.onPhoneNotifications() instead
|
228
231
|
*/
|
229
232
|
onPhoneNotifications(handler) {
|
230
233
|
return this.events.onPhoneNotifications(handler);
|
@@ -233,6 +236,7 @@ class AppSession {
|
|
233
236
|
* ๐ก Listen for VPS coordinates updates
|
234
237
|
* @param handler - Function to handle VPS coordinates
|
235
238
|
* @returns Cleanup function to remove the handler
|
239
|
+
* @deprecated Use session.events.onVpsCoordinates() instead
|
236
240
|
*/
|
237
241
|
onVpsCoordinates(handler) {
|
238
242
|
this.subscribe(types_1.StreamType.VPS_COORDINATES);
|
@@ -242,6 +246,7 @@ class AppSession {
|
|
242
246
|
* ๐ธ Listen for photo responses
|
243
247
|
* @param handler - Function to handle photo response data
|
244
248
|
* @returns Cleanup function to remove the handler
|
249
|
+
* @deprecated Use session.events.onPhotoTaken() instead
|
245
250
|
*/
|
246
251
|
onPhotoTaken(handler) {
|
247
252
|
this.subscribe(types_1.StreamType.PHOTO_TAKEN);
|
@@ -290,7 +295,7 @@ class AppSession {
|
|
290
295
|
// ๐ Connection Management
|
291
296
|
// =====================================
|
292
297
|
/**
|
293
|
-
* ๐ Connect to
|
298
|
+
* ๐ Connect to MentraOS Cloud
|
294
299
|
* @param sessionId - Unique session identifier
|
295
300
|
* @returns Promise that resolves when connected
|
296
301
|
*/
|
@@ -298,7 +303,7 @@ class AppSession {
|
|
298
303
|
this.sessionId = sessionId;
|
299
304
|
// Configure settings API client with the WebSocket URL and session ID
|
300
305
|
// This allows settings to be fetched from the correct server
|
301
|
-
this.settings.configureApiClient(this.config.packageName, this.config.
|
306
|
+
this.settings.configureApiClient(this.config.packageName, this.config.mentraOSWebsocketUrl || '', sessionId);
|
302
307
|
// Update the sessionId in the streaming module
|
303
308
|
if (this.streaming) {
|
304
309
|
Object.defineProperty(this.streaming, 'sessionId', { value: sessionId });
|
@@ -314,15 +319,15 @@ class AppSession {
|
|
314
319
|
this.ws = null;
|
315
320
|
}
|
316
321
|
// Validate WebSocket URL before attempting connection
|
317
|
-
if (!this.config.
|
322
|
+
if (!this.config.mentraOSWebsocketUrl) {
|
318
323
|
this.logger.error('WebSocket URL is missing or undefined');
|
319
324
|
reject(new Error('WebSocket URL is required'));
|
320
325
|
return;
|
321
326
|
}
|
322
327
|
// Add debug logging for connection attempts
|
323
|
-
this.logger.info(`๐๐๐ [${this.config.packageName}] Attempting to connect to: ${this.config.
|
328
|
+
this.logger.info(`๐๐๐ [${this.config.packageName}] Attempting to connect to: ${this.config.mentraOSWebsocketUrl} for session ${this.sessionId}`);
|
324
329
|
// Create connection with error handling
|
325
|
-
this.ws = new ws_1.WebSocket(this.config.
|
330
|
+
this.ws = new ws_1.WebSocket(this.config.mentraOSWebsocketUrl);
|
326
331
|
// Track WebSocket for automatic cleanup
|
327
332
|
this.resources.track(() => {
|
328
333
|
if (this.ws && this.ws.readyState !== 3) { // 3 = CLOSED
|
@@ -513,7 +518,7 @@ class AppSession {
|
|
513
518
|
});
|
514
519
|
}
|
515
520
|
/**
|
516
|
-
* ๐ Disconnect from
|
521
|
+
* ๐ Disconnect from MentraOS Cloud
|
517
522
|
*/
|
518
523
|
disconnect() {
|
519
524
|
// Use the resource tracker to clean up everything
|
@@ -668,13 +673,13 @@ class AppSession {
|
|
668
673
|
* @returns The WebSocket server URL used by this session
|
669
674
|
*/
|
670
675
|
getServerUrl() {
|
671
|
-
return this.config.
|
676
|
+
return this.config.mentraOSWebsocketUrl;
|
672
677
|
}
|
673
678
|
getHttpsServerUrl() {
|
674
|
-
if (!this.config.
|
679
|
+
if (!this.config.mentraOSWebsocketUrl) {
|
675
680
|
return undefined;
|
676
681
|
}
|
677
|
-
return AppSession.convertToHttps(this.config.
|
682
|
+
return AppSession.convertToHttps(this.config.mentraOSWebsocketUrl);
|
678
683
|
}
|
679
684
|
static convertToHttps(rawUrl) {
|
680
685
|
if (!rawUrl)
|
@@ -752,14 +757,14 @@ class AppSession {
|
|
752
757
|
}
|
753
758
|
// Update the settings manager with the new settings
|
754
759
|
this.settings.updateSettings(this.settingsData);
|
755
|
-
// Handle
|
756
|
-
this.logger.debug(`[AppSession] CONNECTION_ACK
|
757
|
-
if (message.
|
758
|
-
this.logger.info(`[AppSession] Calling
|
759
|
-
this.settings.
|
760
|
+
// Handle MentraOS system settings if provided
|
761
|
+
this.logger.debug(`[AppSession] CONNECTION_ACK mentraosSettings:`, message.mentraosSettings);
|
762
|
+
if (message.mentraosSettings) {
|
763
|
+
this.logger.info(`[AppSession] Calling updatementraosSettings with:`, message.mentraosSettings);
|
764
|
+
this.settings.updateMentraosSettings(message.mentraosSettings);
|
760
765
|
}
|
761
766
|
else {
|
762
|
-
this.logger.warn(`[AppSession] CONNECTION_ACK message missing
|
767
|
+
this.logger.warn(`[AppSession] CONNECTION_ACK message missing mentraosSettings field`);
|
763
768
|
}
|
764
769
|
// Handle device capabilities if provided
|
765
770
|
if (message.capabilities) {
|
@@ -834,10 +839,10 @@ class AppSession {
|
|
834
839
|
const changes = this.settings.updateSettings(this.settingsData);
|
835
840
|
// Emit settings update event (for backwards compatibility)
|
836
841
|
this.events.emit('settings_update', this.settingsData);
|
837
|
-
// ---
|
838
|
-
// If the message.settings looks like
|
842
|
+
// --- MentraOS settings update logic ---
|
843
|
+
// If the message.settings looks like MentraOS settings (object with known keys), update mentraosSettings
|
839
844
|
if (message.settings && typeof message.settings === 'object') {
|
840
|
-
this.settings.
|
845
|
+
this.settings.updateMentraosSettings(message.settings);
|
841
846
|
}
|
842
847
|
// Check if we should update subscriptions
|
843
848
|
if (this.shouldUpdateSubscriptionsOnSettingsChange) {
|
@@ -918,9 +923,9 @@ class AppSession {
|
|
918
923
|
}
|
919
924
|
}
|
920
925
|
else if (message.type === 'augmentos_settings_update') {
|
921
|
-
const
|
922
|
-
if (
|
923
|
-
this.settings.
|
926
|
+
const mentraosMsg = message;
|
927
|
+
if (mentraosMsg.settings && typeof mentraosMsg.settings === 'object') {
|
928
|
+
this.settings.updateMentraosSettings(mentraosMsg.settings);
|
924
929
|
}
|
925
930
|
}
|
926
931
|
// Handle 'connection_error' as a specific case if cloud sends this string literal
|
@@ -23,7 +23,7 @@ export declare class LayoutManager {
|
|
23
23
|
* ๐ฏ Creates a new LayoutManager instance
|
24
24
|
*
|
25
25
|
* @param packageName - App package identifier
|
26
|
-
* @param sendMessage - Function to send display requests to
|
26
|
+
* @param sendMessage - Function to send display requests to MentraOS
|
27
27
|
*/
|
28
28
|
constructor(packageName: string, sendMessage: (message: DisplayRequest) => void);
|
29
29
|
/**
|
@@ -24,7 +24,7 @@ class LayoutManager {
|
|
24
24
|
* ๐ฏ Creates a new LayoutManager instance
|
25
25
|
*
|
26
26
|
* @param packageName - App package identifier
|
27
|
-
* @param sendMessage - Function to send display requests to
|
27
|
+
* @param sendMessage - Function to send display requests to MentraOS
|
28
28
|
*/
|
29
29
|
constructor(packageName, sendMessage) {
|
30
30
|
this.packageName = packageName;
|