@mentra/sdk 2.1.31-beta.6 → 3.0.0-alpha.1
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 +54 -9
- package/dist/MiniAppServer.d.ts +58 -0
- package/dist/MiniAppServer.d.ts.map +1 -0
- package/dist/app/server/index.d.ts +152 -88
- package/dist/app/server/index.d.ts.map +1 -1
- package/dist/app/session/events.d.ts +20 -3
- package/dist/app/session/events.d.ts.map +1 -1
- package/dist/app/session/index.d.ts +56 -3
- package/dist/app/session/index.d.ts.map +1 -1
- package/dist/app/session/modules/audio-output-stream.d.ts +108 -0
- package/dist/app/session/modules/audio-output-stream.d.ts.map +1 -0
- package/dist/app/session/modules/audio.d.ts +36 -1
- package/dist/app/session/modules/audio.d.ts.map +1 -1
- package/dist/app/session/modules/camera-managed-extension.d.ts +37 -33
- package/dist/app/session/modules/camera-managed-extension.d.ts.map +1 -1
- package/dist/app/session/modules/camera.d.ts +108 -50
- package/dist/app/session/modules/camera.d.ts.map +1 -1
- package/dist/app/session/modules/index.d.ts +4 -3
- package/dist/app/session/modules/index.d.ts.map +1 -1
- package/dist/app/session/modules/led.d.ts.map +1 -1
- package/dist/app/session/modules/location.d.ts.map +1 -1
- package/dist/app/session/settings.d.ts +5 -1
- package/dist/app/session/settings.d.ts.map +1 -1
- package/dist/app/webview/index.d.ts +67 -9
- package/dist/app/webview/index.d.ts.map +1 -1
- package/dist/constants/log-messages/updates.d.ts +32 -9
- package/dist/constants/log-messages/updates.d.ts.map +1 -1
- package/dist/constants/log-messages/warning.d.ts +12 -0
- package/dist/constants/log-messages/warning.d.ts.map +1 -1
- package/dist/display-utils.d.ts +3 -1
- package/dist/display-utils.d.ts.map +1 -1
- package/dist/display-utils.js +443 -26
- package/dist/display-utils.js.map +10 -6
- package/dist/index.d.ts +22 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8824 -4229
- package/dist/index.js.map +63 -31
- package/dist/internal/_SessionManager.d.ts +76 -0
- package/dist/internal/_SessionManager.d.ts.map +1 -0
- package/dist/logging/clean-transport.d.ts +50 -0
- package/dist/logging/clean-transport.d.ts.map +1 -0
- package/dist/logging/errors.d.ts +90 -0
- package/dist/logging/errors.d.ts.map +1 -0
- package/dist/logging/logger.d.ts +72 -1
- package/dist/logging/logger.d.ts.map +1 -1
- package/dist/logging/telemetry-transport.d.ts +51 -0
- package/dist/logging/telemetry-transport.d.ts.map +1 -0
- package/dist/session/DataStreamRouter.d.ts +219 -0
- package/dist/session/DataStreamRouter.d.ts.map +1 -0
- package/dist/session/MentraSession.d.ts +102 -0
- package/dist/session/MentraSession.d.ts.map +1 -0
- package/dist/session/index.d.ts +2 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/internal/_ConnectionManager.d.ts +43 -0
- package/dist/session/internal/_ConnectionManager.d.ts.map +1 -0
- package/dist/session/internal/_MessageRouter.d.ts +11 -0
- package/dist/session/internal/_MessageRouter.d.ts.map +1 -0
- package/dist/session/internal/_SubscriptionManager.d.ts +32 -0
- package/dist/session/internal/_SubscriptionManager.d.ts.map +1 -0
- package/dist/session/internal/_V2AudioStreamShim.d.ts +12 -0
- package/dist/session/internal/_V2AudioStreamShim.d.ts.map +1 -0
- package/dist/session/internal/_V2CameraShim.d.ts +52 -0
- package/dist/session/internal/_V2CameraShim.d.ts.map +1 -0
- package/dist/session/internal/_V2EventManagerShim.d.ts +52 -0
- package/dist/session/internal/_V2EventManagerShim.d.ts.map +1 -0
- package/dist/session/internal/_V2SessionShim.d.ts +169 -0
- package/dist/session/internal/_V2SessionShim.d.ts.map +1 -0
- package/dist/session/internal/_V2SettingsShim.d.ts +17 -0
- package/dist/session/internal/_V2SettingsShim.d.ts.map +1 -0
- package/dist/session/managers/CameraManager.d.ts +198 -0
- package/dist/session/managers/CameraManager.d.ts.map +1 -0
- package/dist/session/managers/DashboardManager.d.ts +131 -0
- package/dist/session/managers/DashboardManager.d.ts.map +1 -0
- package/dist/session/managers/DeviceManager.d.ts +348 -0
- package/dist/session/managers/DeviceManager.d.ts.map +1 -0
- package/dist/session/managers/DisplayManager.d.ts +171 -0
- package/dist/session/managers/DisplayManager.d.ts.map +1 -0
- package/dist/session/managers/LedManager.d.ts +116 -0
- package/dist/session/managers/LedManager.d.ts.map +1 -0
- package/dist/session/managers/LocationManager.d.ts +224 -0
- package/dist/session/managers/LocationManager.d.ts.map +1 -0
- package/dist/session/managers/MicManager.d.ts +252 -0
- package/dist/session/managers/MicManager.d.ts.map +1 -0
- package/dist/session/managers/PermissionsManager.d.ts +139 -0
- package/dist/session/managers/PermissionsManager.d.ts.map +1 -0
- package/dist/session/managers/PhoneManager.d.ts +351 -0
- package/dist/session/managers/PhoneManager.d.ts.map +1 -0
- package/dist/session/managers/SpeakerManager.d.ts +285 -0
- package/dist/session/managers/SpeakerManager.d.ts.map +1 -0
- package/dist/session/managers/StorageManager.d.ts +289 -0
- package/dist/session/managers/StorageManager.d.ts.map +1 -0
- package/dist/session/managers/TimeUtils.d.ts +175 -0
- package/dist/session/managers/TimeUtils.d.ts.map +1 -0
- package/dist/session/managers/TranscriptionManager.d.ts +195 -0
- package/dist/session/managers/TranscriptionManager.d.ts.map +1 -0
- package/dist/session/managers/TranslationManager.d.ts +189 -0
- package/dist/session/managers/TranslationManager.d.ts.map +1 -0
- package/dist/session.d.ts +41 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +4110 -0
- package/dist/session.js.map +44 -0
- package/dist/transport/Transport.d.ts +119 -0
- package/dist/transport/Transport.d.ts.map +1 -0
- package/dist/transport/WebSocketTransport.d.ts +73 -0
- package/dist/transport/WebSocketTransport.d.ts.map +1 -0
- package/dist/types/index.d.ts +31 -5
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/message-types.d.ts +25 -9
- package/dist/types/message-types.d.ts.map +1 -1
- package/dist/types/messages/app-to-cloud.d.ts +113 -16
- package/dist/types/messages/app-to-cloud.d.ts.map +1 -1
- package/dist/types/messages/cloud-to-app.d.ts +50 -4
- package/dist/types/messages/cloud-to-app.d.ts.map +1 -1
- package/dist/types/messages/cloud-to-glasses.d.ts +43 -14
- package/dist/types/messages/cloud-to-glasses.d.ts.map +1 -1
- package/dist/types/messages/glasses-to-cloud.d.ts +5 -5
- package/dist/types/messages/glasses-to-cloud.d.ts.map +1 -1
- package/dist/types/models.d.ts +17 -0
- package/dist/types/models.d.ts.map +1 -1
- package/dist/types/rtmp-stream.d.ts +4 -4
- package/dist/types/rtmp-stream.d.ts.map +1 -1
- package/dist/types/streams.d.ts +6 -1
- package/dist/types/streams.d.ts.map +1 -1
- package/dist/types/webhooks.d.ts +11 -0
- package/dist/types/webhooks.d.ts.map +1 -1
- package/dist/utils/error-utils.d.ts +139 -0
- package/dist/utils/error-utils.d.ts.map +1 -0
- package/dist/utils/permissions-utils.d.ts +30 -7
- package/dist/utils/permissions-utils.d.ts.map +1 -1
- package/node_modules/@mentra/types/dist/applet.d.ts +5 -1
- package/node_modules/@mentra/types/dist/applet.d.ts.map +1 -1
- package/node_modules/@mentra/types/dist/capabilities/even-realities-g2.d.ts +12 -0
- package/node_modules/@mentra/types/dist/capabilities/even-realities-g2.d.ts.map +1 -0
- package/node_modules/@mentra/types/dist/capabilities/even-realities-g2.js +61 -0
- package/node_modules/@mentra/types/dist/capabilities/mentra-display.d.ts +12 -0
- package/node_modules/@mentra/types/dist/capabilities/mentra-display.d.ts.map +1 -0
- package/node_modules/@mentra/types/dist/capabilities/mentra-display.js +54 -0
- package/node_modules/@mentra/types/dist/capabilities/none.d.ts +13 -0
- package/node_modules/@mentra/types/dist/capabilities/none.d.ts.map +1 -0
- package/node_modules/@mentra/types/dist/capabilities/none.js +67 -0
- package/node_modules/@mentra/types/dist/enums.d.ts +8 -2
- package/node_modules/@mentra/types/dist/enums.d.ts.map +1 -1
- package/node_modules/@mentra/types/dist/enums.js +9 -2
- package/node_modules/@mentra/types/dist/hardware.d.ts +3 -1
- package/node_modules/@mentra/types/dist/hardware.d.ts.map +1 -1
- package/node_modules/@mentra/types/dist/hardware.js +12 -2
- package/node_modules/@mentra/types/dist/index.d.ts +1 -1
- package/node_modules/@mentra/types/dist/index.d.ts.map +1 -1
- package/node_modules/@mentra/types/dist/index.js +2 -1
- package/node_modules/@mentra/types/package.json +2 -2
- package/package.json +24 -12
- package/dist/examples/managed-rtmp-streaming-example.d.ts +0 -2
- package/dist/examples/managed-rtmp-streaming-example.d.ts.map +0 -1
- package/dist/examples/managed-rtmp-streaming-with-restream-example.d.ts +0 -11
- package/dist/examples/managed-rtmp-streaming-with-restream-example.d.ts.map +0 -1
- package/dist/examples/rtmp-streaming-example.d.ts +0 -2
- package/dist/examples/rtmp-streaming-example.d.ts.map +0 -1
- package/node_modules/@mentra/types/src/applet.ts +0 -51
- package/node_modules/@mentra/types/src/capabilities/even-realities-g1.ts +0 -63
- package/node_modules/@mentra/types/src/capabilities/mentra-live.ts +0 -103
- package/node_modules/@mentra/types/src/capabilities/simulated-glasses.ts +0 -76
- package/node_modules/@mentra/types/src/capabilities/vuzix-z100.ts +0 -60
- package/node_modules/@mentra/types/src/cli.ts +0 -169
- package/node_modules/@mentra/types/src/device.ts +0 -43
- package/node_modules/@mentra/types/src/enums.ts +0 -36
- package/node_modules/@mentra/types/src/hardware.ts +0 -172
- package/node_modules/@mentra/types/src/index.ts +0 -64
- package/node_modules/@mentra/types/tsconfig.json +0 -22
- package/node_modules/@mentra/types/tsconfig.tsbuildinfo +0 -1
package/README.md
CHANGED
|
@@ -1,14 +1,56 @@
|
|
|
1
1
|
# @mentra/sdk
|
|
2
2
|
|
|
3
|
-
Build apps for MentraOS
|
|
3
|
+
Build apps for MentraOS smart glasses.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import { MiniAppServer } from "@mentra/sdk";
|
|
9
|
+
|
|
10
|
+
const app = new MiniAppServer({
|
|
11
|
+
packageName: "com.example.myapp",
|
|
12
|
+
apiKey: process.env.API_KEY!,
|
|
13
|
+
port: 3000,
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
app.onSession((session) => {
|
|
17
|
+
session.transcription.on((data) => {
|
|
18
|
+
session.display.showTextWall(data.text);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
await app.start();
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Session Managers
|
|
26
|
+
|
|
27
|
+
| Manager | Access | What it does |
|
|
28
|
+
|---------|--------|-------------|
|
|
29
|
+
| Transcription | `session.transcription` | Real-time speech-to-text |
|
|
30
|
+
| Translation | `session.translation` | Real-time translation |
|
|
31
|
+
| Display | `session.display` | Show text and graphics on the glasses |
|
|
32
|
+
| Camera | `session.camera` | Take photos and stream video |
|
|
33
|
+
| Speaker | `session.speaker` | Play audio and text-to-speech |
|
|
34
|
+
| Mic | `session.mic` | Raw audio input and voice activity detection |
|
|
35
|
+
| Device | `session.device` | Hardware state, battery, connection, events |
|
|
36
|
+
| Phone | `session.phone` | Notifications, calendar, phone battery |
|
|
37
|
+
| Location | `session.location` | GPS coordinates |
|
|
38
|
+
| Storage | `session.storage` | Persistent key-value storage |
|
|
39
|
+
| Permissions | `session.permissions` | Check app permissions at runtime |
|
|
40
|
+
| LED | `session.led` | Control the LED light |
|
|
41
|
+
| Dashboard | `session.dashboard` | Write to the system dashboard view |
|
|
42
|
+
| Time | `session.time` | Timezone-aware time utilities |
|
|
43
|
+
|
|
44
|
+
## Migrating from v2?
|
|
45
|
+
|
|
46
|
+
See the [migration guide](https://docs.mentra.glass/app-devs/migration/overview). Your existing code still works — v3 includes a compatibility layer.
|
|
4
47
|
|
|
5
48
|
## Prerequisites
|
|
6
49
|
|
|
7
|
-
- Node.js (v18 or later)
|
|
8
|
-
- Bun
|
|
50
|
+
- Node.js (v18 or later) or Bun
|
|
9
51
|
- Basic TypeScript knowledge
|
|
10
52
|
|
|
11
|
-
##
|
|
53
|
+
## Getting Started
|
|
12
54
|
|
|
13
55
|
The quickest way to get started is using our example app. This guide assumes you have a pair of [compatible smart glasses](https://mentra.glass/os) connected to a phone running the [MentraOS app](https://mentra.glass/install).
|
|
14
56
|
|
|
@@ -92,11 +134,14 @@ We are going to use ngrok to expose your local app to the internet. This is usef
|
|
|
92
134
|
|
|
93
135
|
For more information, visit the [MentraOS-Cloud-Example-App repository](https://github.com/Mentra-Community/MentraOS-Cloud-Example-App). For a more in-depth example with app settings support, see the [Extended Example](https://github.com/Mentra-Community/MentraOS-Extended-Example-App).
|
|
94
136
|
|
|
95
|
-
##
|
|
137
|
+
## Documentation
|
|
96
138
|
|
|
97
|
-
-
|
|
98
|
-
-
|
|
139
|
+
- [Getting Started](https://docs.mentra.glass/app-devs/getting-started/quickstart)
|
|
140
|
+
- [API Reference](https://docs.mentra.glass/app-devs/core-concepts/session)
|
|
141
|
+
- [Migration Guide (v2 → v3)](https://docs.mentra.glass/app-devs/migration/overview)
|
|
142
|
+
- [Full API Map](https://docs.mentra.glass/app-devs/migration/api-map)
|
|
143
|
+
- [Discord Community](https://discord.gg/5ukNvkEAqT)
|
|
99
144
|
|
|
100
|
-
##
|
|
145
|
+
## License
|
|
101
146
|
|
|
102
|
-
MIT
|
|
147
|
+
MIT
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { Context } from "hono";
|
|
2
|
+
import type { ToolCall } from "./types";
|
|
3
|
+
import type { AuthVariables, SessionWebhookRequest, StopWebhookRequest } from "./types";
|
|
4
|
+
import { AppServer, type AppServerConfig } from "./app/server";
|
|
5
|
+
import { AppSession } from "./app/session";
|
|
6
|
+
import { MentraSession } from "./session";
|
|
7
|
+
import { type _ToolCallHandler } from "./internal/_SessionManager";
|
|
8
|
+
export type MiniAppServerConfig = AppServerConfig;
|
|
9
|
+
export type SessionHandler = (session: MentraSession) => void | Promise<void>;
|
|
10
|
+
export type StopHandler = (session: MentraSession | null, reason: string) => void | Promise<void>;
|
|
11
|
+
export type ToolCallHandler = _ToolCallHandler;
|
|
12
|
+
/**
|
|
13
|
+
* v3 cloud/server host for Mentra mini apps.
|
|
14
|
+
*
|
|
15
|
+
* `MiniAppServer` is the cloud-only entry point. It handles HTTP endpoints
|
|
16
|
+
* (webhooks, tools, settings, health, photo-upload) and creates MentraSession
|
|
17
|
+
* instances for each connected user.
|
|
18
|
+
*
|
|
19
|
+
* Naming:
|
|
20
|
+
* - `MiniAppServer` is cloud/server-specific (not needed for local apps).
|
|
21
|
+
* - `MentraSession` is the per-user session abstraction (same everywhere).
|
|
22
|
+
*
|
|
23
|
+
* This class extends the v2 `AppServer` during the transition period.
|
|
24
|
+
* When a v3-style callback is registered via `app.onSession((session) => {...})`,
|
|
25
|
+
* webhook lifecycle flows through `_SessionManager` → `MentraSession` → v3 runtime.
|
|
26
|
+
* When a v2-style subclass overrides `onSession(session, sessionId, userId)`,
|
|
27
|
+
* it goes through the old `AppServer` path entirely.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* const app = new MiniAppServer({ packageName: "com.example.myapp", apiKey: "..." })
|
|
32
|
+
*
|
|
33
|
+
* app.onSession((session) => {
|
|
34
|
+
* session.transcription.on((data) => {
|
|
35
|
+
* session.display.showText(data.text)
|
|
36
|
+
* })
|
|
37
|
+
* })
|
|
38
|
+
*
|
|
39
|
+
* await app.start()
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare class MiniAppServer extends AppServer {
|
|
43
|
+
private readonly _sessions;
|
|
44
|
+
constructor(config: MiniAppServerConfig);
|
|
45
|
+
onSession(handler: SessionHandler): this;
|
|
46
|
+
onSession(session: AppSession, sessionId: string, userId: string): Promise<void>;
|
|
47
|
+
onStop(handler: StopHandler): this;
|
|
48
|
+
onStop(sessionId: string, userId: string, reason: string): Promise<void>;
|
|
49
|
+
onToolCall(handler: ToolCallHandler): this;
|
|
50
|
+
onToolCall(toolCall: ToolCall): Promise<string | undefined>;
|
|
51
|
+
protected handleSessionWebhookRequest(request: SessionWebhookRequest, c: Context<{
|
|
52
|
+
Variables: AuthVariables;
|
|
53
|
+
}>): Promise<Response>;
|
|
54
|
+
protected handleStopWebhookRequest(request: StopWebhookRequest, c: Context<{
|
|
55
|
+
Variables: AuthVariables;
|
|
56
|
+
}>): Promise<Response>;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=MiniAppServer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MiniAppServer.d.ts","sourceRoot":"","sources":["../src/MiniAppServer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,KAAK,EAAE,aAAa,EAAE,qBAAqB,EAAE,kBAAkB,EAAmB,MAAM,SAAS,CAAC;AACzG,OAAO,EAAE,SAAS,EAAE,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAmB,KAAK,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AASpF,MAAM,MAAM,mBAAmB,GAAG,eAAe,CAAC;AAElD,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,EAAE,aAAa,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAC9E,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAClG,MAAM,MAAM,eAAe,GAAG,gBAAgB,CAAC;AAE/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,qBAAa,aAAc,SAAQ,SAAS;IAC1C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAkB;gBAEhC,MAAM,EAAE,mBAAmB;IAgBhC,SAAS,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI;IAC/B,SAAS,CAAC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBzF,MAAM,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI;IACzB,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAUjF,UAAU,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI;IACjC,UAAU,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;cAYlD,2BAA2B,CAClD,OAAO,EAAE,qBAAqB,EAC9B,CAAC,EAAE,OAAO,CAAC;QAAE,SAAS,EAAE,aAAa,CAAA;KAAE,CAAC,GACvC,OAAO,CAAC,QAAQ,CAAC;cAgCK,wBAAwB,CAC/C,OAAO,EAAE,kBAAkB,EAC3B,CAAC,EAAE,OAAO,CAAC;QAAE,SAAS,EAAE,aAAa,CAAA;KAAE,CAAC,GACvC,OAAO,CAAC,QAAQ,CAAC;CAgBrB"}
|
|
@@ -1,29 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* Creates and manages a server for Apps in the MentraOS ecosystem.
|
|
5
|
-
* Handles webhook endpoints, session management, and cleanup.
|
|
6
|
-
*/
|
|
7
|
-
import { type Express } from "express";
|
|
8
|
-
import { AppSession } from "../session/index";
|
|
9
|
-
import { ToolCall } from "../../types";
|
|
1
|
+
import { Hono } from "hono";
|
|
2
|
+
import type { Context } from "hono";
|
|
10
3
|
import { Logger } from "pino";
|
|
11
|
-
import {
|
|
4
|
+
import { SessionWebhookRequest, StopWebhookRequest, ToolCall, AuthVariables } from "../../types";
|
|
5
|
+
import { AppSession } from "../session/index";
|
|
6
|
+
import type { PhotoData } from "../../types/photo-data";
|
|
12
7
|
export declare const GIVE_APP_CONTROL_OF_TOOL_RESPONSE: string;
|
|
13
8
|
/**
|
|
14
|
-
* Pending photo request stored at AppServer level
|
|
9
|
+
* Pending photo request stored at AppServer level for reconnection resilience.
|
|
15
10
|
* This allows O(1) lookup when photo uploads arrive via HTTP,
|
|
16
11
|
* and survives session reconnections.
|
|
17
12
|
* See: cloud/issues/019-sdk-photo-request-architecture
|
|
18
13
|
*/
|
|
19
|
-
|
|
14
|
+
interface PendingPhotoRequest {
|
|
20
15
|
userId: string;
|
|
21
16
|
sessionId: string;
|
|
22
17
|
session: AppSession;
|
|
23
18
|
resolve: (photo: PhotoData) => void;
|
|
24
19
|
reject: (error: Error) => void;
|
|
25
20
|
timestamp: number;
|
|
26
|
-
timeoutId?:
|
|
21
|
+
timeoutId?: ReturnType<typeof setTimeout>;
|
|
27
22
|
}
|
|
28
23
|
/**
|
|
29
24
|
* 🔧 Configuration options for App Server
|
|
@@ -63,11 +58,35 @@ export interface AppServerConfig {
|
|
|
63
58
|
cookieSecret?: string;
|
|
64
59
|
/** App instructions string shown to the user */
|
|
65
60
|
appInstructions?: string;
|
|
61
|
+
/**
|
|
62
|
+
* Enable verbose SDK logging. Shows all internal SDK messages in the terminal
|
|
63
|
+
* (WebSocket lifecycle, subscription updates, message routing, etc.).
|
|
64
|
+
* Useful for debugging connection and streaming issues.
|
|
65
|
+
*
|
|
66
|
+
* Can also be enabled with the MENTRA_VERBOSE=true environment variable.
|
|
67
|
+
* This config option takes priority over the env var.
|
|
68
|
+
*/
|
|
69
|
+
verbose?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* SDK log level. Controls which log messages appear in the terminal.
|
|
72
|
+
* - 'error': Only errors
|
|
73
|
+
* - 'warn': Errors and warnings
|
|
74
|
+
* - 'info': Normal operation (default)
|
|
75
|
+
* - 'debug': Everything including SDK internals (implies verbose)
|
|
76
|
+
*
|
|
77
|
+
* Can also be set with the MENTRA_LOG_LEVEL environment variable.
|
|
78
|
+
* This config option takes priority over the env var.
|
|
79
|
+
*/
|
|
80
|
+
logLevel?: "error" | "warn" | "info" | "debug";
|
|
66
81
|
}
|
|
82
|
+
type AppHono = Hono<{
|
|
83
|
+
Variables: AuthVariables;
|
|
84
|
+
}>;
|
|
67
85
|
/**
|
|
68
86
|
* 🎯 App Server Implementation
|
|
69
87
|
*
|
|
70
|
-
* Base class for creating App servers.
|
|
88
|
+
* Base class for creating App servers, now extending Hono for a modern API.
|
|
89
|
+
* Handles:
|
|
71
90
|
* - 🔄 Session lifecycle management
|
|
72
91
|
* - 📡 Webhook endpoints for MentraOS Cloud
|
|
73
92
|
* - 📂 Static file serving
|
|
@@ -77,6 +96,13 @@ export interface AppServerConfig {
|
|
|
77
96
|
* @example
|
|
78
97
|
* ```typescript
|
|
79
98
|
* class MyAppServer extends AppServer {
|
|
99
|
+
* constructor(config: AppServerConfig) {
|
|
100
|
+
* super(config)
|
|
101
|
+
*
|
|
102
|
+
* // Add custom API routes (Hono syntax)
|
|
103
|
+
* this.get("/api/custom", (c) => c.json({ message: "Hello!" }))
|
|
104
|
+
* }
|
|
105
|
+
*
|
|
80
106
|
* protected async onSession(session: AppSession, sessionId: string, userId: string) {
|
|
81
107
|
* // Handle new user sessions here
|
|
82
108
|
* session.events.onTranscription((data) => {
|
|
@@ -88,24 +114,22 @@ export interface AppServerConfig {
|
|
|
88
114
|
* const server = new MyAppServer({
|
|
89
115
|
* packageName: 'org.example.myapp',
|
|
90
116
|
* apiKey: 'your_api_key',
|
|
91
|
-
* publicDir: "/public",
|
|
92
117
|
* });
|
|
93
118
|
*
|
|
94
119
|
* await server.start();
|
|
95
120
|
* ```
|
|
96
121
|
*/
|
|
97
|
-
export declare class AppServer {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
122
|
+
export declare class AppServer extends Hono<{
|
|
123
|
+
Variables: AuthVariables;
|
|
124
|
+
}> {
|
|
125
|
+
/** Server configuration */
|
|
126
|
+
protected config: AppServerConfig;
|
|
101
127
|
/** Map of active user sessions by sessionId */
|
|
102
128
|
private activeSessions;
|
|
103
129
|
/** Map of active user sessions by userId */
|
|
104
130
|
private activeSessionsByUserId;
|
|
105
|
-
/**
|
|
106
|
-
private
|
|
107
|
-
/** App instructions string shown to the user */
|
|
108
|
-
private appInstructions;
|
|
131
|
+
/** Guards against running cleanup twice (double Ctrl-C, SIGINT+SIGTERM, etc.) */
|
|
132
|
+
private _cleanupPromise;
|
|
109
133
|
/**
|
|
110
134
|
* Pending photo requests by requestId - owned by AppServer for HTTP endpoint access.
|
|
111
135
|
* This is the single source of truth for pending photo requests.
|
|
@@ -116,9 +140,21 @@ export declare class AppServer {
|
|
|
116
140
|
* See: cloud/issues/019-sdk-photo-request-architecture
|
|
117
141
|
*/
|
|
118
142
|
private pendingPhotoRequests;
|
|
143
|
+
/** Array of cleanup handlers to run on shutdown */
|
|
144
|
+
private cleanupHandlers;
|
|
145
|
+
/** App instructions string shown to the user */
|
|
146
|
+
private appInstructions;
|
|
119
147
|
readonly logger: Logger;
|
|
120
148
|
constructor(config: AppServerConfig);
|
|
121
|
-
|
|
149
|
+
/**
|
|
150
|
+
* @deprecated Use `this.get()`, `this.post()`, etc. directly since AppServer now extends Hono
|
|
151
|
+
* This method is kept for backward compatibility during migration.
|
|
152
|
+
*/
|
|
153
|
+
getExpressApp(): AppHono;
|
|
154
|
+
/**
|
|
155
|
+
* Get the Hono app instance (returns this since AppServer extends Hono)
|
|
156
|
+
*/
|
|
157
|
+
getHonoApp(): AppHono;
|
|
122
158
|
/**
|
|
123
159
|
* 👥 Session Handler
|
|
124
160
|
* Override this method to handle new App sessions.
|
|
@@ -148,15 +184,37 @@ export declare class AppServer {
|
|
|
148
184
|
* @returns Optional string response that will be sent back to MentraOS Cloud
|
|
149
185
|
*/
|
|
150
186
|
protected onToolCall(toolCall: ToolCall): Promise<string | undefined>;
|
|
187
|
+
protected getActiveSessionById(sessionId: string): AppSession | null;
|
|
188
|
+
protected getActiveSessionForUser(userId: string): AppSession | null;
|
|
189
|
+
protected setActiveSession(sessionId: string, userId: string, session: AppSession): void;
|
|
190
|
+
protected removeActiveSession(sessionId: string, userId: string): void;
|
|
151
191
|
/**
|
|
152
|
-
* 🚀
|
|
153
|
-
*
|
|
192
|
+
* 🚀 Initialize the App
|
|
193
|
+
* Sets up logging and checks SDK version.
|
|
194
|
+
* After calling this, use Bun.serve() with app.fetch to start the server.
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* ```typescript
|
|
198
|
+
* const app = new MyAppServer({ ... })
|
|
199
|
+
* await app.start()
|
|
154
200
|
*
|
|
155
|
-
*
|
|
201
|
+
* Bun.serve({
|
|
202
|
+
* port: 3333,
|
|
203
|
+
* routes: { "/*": indexHtml },
|
|
204
|
+
* fetch: app.fetch,
|
|
205
|
+
* })
|
|
206
|
+
* ```
|
|
207
|
+
*
|
|
208
|
+
* @returns Promise that resolves when initialization is complete
|
|
156
209
|
*/
|
|
157
210
|
start(): Promise<void>;
|
|
158
211
|
/**
|
|
159
|
-
*
|
|
212
|
+
* Check and log SDK version (dist-tag aware).
|
|
213
|
+
* Hits npm registry directly — no dependency on our backend.
|
|
214
|
+
*/
|
|
215
|
+
private checkSDKVersion;
|
|
216
|
+
/**
|
|
217
|
+
* Stop the Server
|
|
160
218
|
* Gracefully shuts down the server and cleans up all sessions.
|
|
161
219
|
*/
|
|
162
220
|
stop(): Promise<void>;
|
|
@@ -171,48 +229,94 @@ export declare class AppServer {
|
|
|
171
229
|
*/
|
|
172
230
|
protected generateToken(userId: string, sessionId: string, secretKey: string): string;
|
|
173
231
|
/**
|
|
174
|
-
*
|
|
232
|
+
* Add Cleanup Handler
|
|
175
233
|
* Register a function to be called during server shutdown.
|
|
176
234
|
*
|
|
177
235
|
* @param handler - Function to call during cleanup
|
|
178
236
|
*/
|
|
179
237
|
protected addCleanupHandler(handler: () => void): void;
|
|
180
238
|
/**
|
|
181
|
-
*
|
|
239
|
+
* Register a pending photo request.
|
|
240
|
+
* Called by CameraModule when a photo is requested.
|
|
241
|
+
* Stores the request at AppServer level for O(1) lookup when HTTP response arrives.
|
|
242
|
+
*
|
|
243
|
+
* @param requestId - Unique identifier for this photo request
|
|
244
|
+
* @param request - Request details including session, resolve/reject callbacks
|
|
245
|
+
*/
|
|
246
|
+
registerPhotoRequest(requestId: string, request: Omit<PendingPhotoRequest, "timeoutId">): void;
|
|
247
|
+
/**
|
|
248
|
+
* Get a pending photo request by ID.
|
|
249
|
+
*
|
|
250
|
+
* @param requestId - The request ID to look up
|
|
251
|
+
* @returns The pending request, or undefined if not found
|
|
252
|
+
*/
|
|
253
|
+
getPhotoRequest(requestId: string): PendingPhotoRequest | undefined;
|
|
254
|
+
/**
|
|
255
|
+
* Complete a photo request (success or error).
|
|
256
|
+
* Clears the timeout and removes from the pending map.
|
|
257
|
+
*
|
|
258
|
+
* @param requestId - The request ID to complete
|
|
259
|
+
* @returns The pending request that was completed, or undefined if not found
|
|
260
|
+
*/
|
|
261
|
+
completePhotoRequest(requestId: string): PendingPhotoRequest | undefined;
|
|
262
|
+
/**
|
|
263
|
+
* Clean up all pending photo requests for a session.
|
|
264
|
+
* Called when a session permanently disconnects.
|
|
265
|
+
*
|
|
266
|
+
* @param sessionId - The session ID to clean up requests for
|
|
267
|
+
*/
|
|
268
|
+
cleanupPhotoRequestsForSession(sessionId: string): void;
|
|
269
|
+
/**
|
|
270
|
+
* Setup Webhook Endpoint
|
|
182
271
|
* Creates the webhook endpoint that MentraOS Cloud calls to start new sessions.
|
|
183
272
|
*/
|
|
184
273
|
private setupWebhook;
|
|
185
274
|
/**
|
|
186
|
-
*
|
|
275
|
+
* Setup Tool Call Endpoint
|
|
187
276
|
* Creates a /tool endpoint for handling tool calls from MentraOS Cloud.
|
|
188
277
|
*/
|
|
189
278
|
private setupToolCallEndpoint;
|
|
190
279
|
/**
|
|
191
280
|
* Handle a session request webhook
|
|
192
281
|
*/
|
|
193
|
-
|
|
282
|
+
protected handleSessionWebhookRequest(request: SessionWebhookRequest, c: Context<{
|
|
283
|
+
Variables: AuthVariables;
|
|
284
|
+
}>): Promise<Response>;
|
|
194
285
|
/**
|
|
195
286
|
* Handle a stop request webhook
|
|
196
287
|
*/
|
|
197
|
-
|
|
288
|
+
protected handleStopWebhookRequest(request: StopWebhookRequest, c: Context<{
|
|
289
|
+
Variables: AuthVariables;
|
|
290
|
+
}>): Promise<Response>;
|
|
198
291
|
/**
|
|
199
|
-
*
|
|
292
|
+
* Setup Health Check Endpoint
|
|
200
293
|
* Creates a /health endpoint for monitoring server status.
|
|
201
294
|
*/
|
|
202
295
|
private setupHealthCheck;
|
|
203
296
|
/**
|
|
204
|
-
*
|
|
297
|
+
* Setup Settings Endpoint
|
|
205
298
|
* Creates a /settings endpoint that the MentraOS Cloud can use to update settings.
|
|
206
299
|
*/
|
|
207
300
|
private setupSettingsEndpoint;
|
|
208
301
|
/**
|
|
209
|
-
*
|
|
210
|
-
* Configures
|
|
302
|
+
* Setup Static File Serving
|
|
303
|
+
* Configures Hono to serve static files from the specified directory.
|
|
211
304
|
*/
|
|
212
305
|
private setupPublicDir;
|
|
213
306
|
/**
|
|
214
|
-
*
|
|
215
|
-
*
|
|
307
|
+
* Setup Shutdown Handlers
|
|
308
|
+
*
|
|
309
|
+
* Both SIGINT (Ctrl+C) and SIGTERM (Kubernetes) → fast exit.
|
|
310
|
+
*
|
|
311
|
+
* We never release ownership on shutdown (cloud will resurrect), so
|
|
312
|
+
* there is nothing useful to clean up. The only thing worth doing is
|
|
313
|
+
* a best-effort SimpleStorage flush, which we fire-and-forget.
|
|
314
|
+
*
|
|
315
|
+
* process.exit() does NOT work reliably under `bun --watch` — it
|
|
316
|
+
* intercepts the call. Instead we remove all JS signal handlers and
|
|
317
|
+
* re-raise the signal so the OS default handler terminates us.
|
|
318
|
+
*
|
|
319
|
+
* See: cloud/issues/086-sdk-fast-shutdown
|
|
216
320
|
*/
|
|
217
321
|
private setupShutdown;
|
|
218
322
|
/**
|
|
@@ -238,70 +342,30 @@ export declare class AppServer {
|
|
|
238
342
|
*/
|
|
239
343
|
private setupPhotoUploadEndpoint;
|
|
240
344
|
/**
|
|
241
|
-
*
|
|
242
|
-
*
|
|
243
|
-
* Stores the request at AppServer level for O(1) lookup when HTTP response arrives.
|
|
244
|
-
*
|
|
245
|
-
* @param requestId - Unique identifier for this photo request
|
|
246
|
-
* @param request - Request details including session, resolve/reject callbacks
|
|
247
|
-
*/
|
|
248
|
-
registerPhotoRequest(requestId: string, request: Omit<PendingPhotoRequest, "timeoutId">): void;
|
|
249
|
-
/**
|
|
250
|
-
* Get a pending photo request by ID.
|
|
251
|
-
*
|
|
252
|
-
* @param requestId - The request ID to look up
|
|
253
|
-
* @returns The pending request, or undefined if not found
|
|
254
|
-
*/
|
|
255
|
-
getPhotoRequest(requestId: string): PendingPhotoRequest | undefined;
|
|
256
|
-
/**
|
|
257
|
-
* Complete a photo request (success or error).
|
|
258
|
-
* Clears the timeout and removes from the pending map.
|
|
259
|
-
*
|
|
260
|
-
* @param requestId - The request ID to complete
|
|
261
|
-
* @returns The pending request that was completed, or undefined if not found
|
|
345
|
+
* Setup Mentra Auth Redirect Endpoint
|
|
346
|
+
* Creates a /mentra-auth endpoint that redirects to the MentraOS OAuth flow.
|
|
262
347
|
*/
|
|
263
|
-
|
|
348
|
+
private setupMentraAuthRedirect;
|
|
264
349
|
/**
|
|
265
|
-
*
|
|
266
|
-
* Called when a session permanently disconnects.
|
|
350
|
+
* Setup SDK-owned webview auth routes.
|
|
267
351
|
*
|
|
268
|
-
*
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
/**
|
|
272
|
-
* 🔐 Setup Mentra Auth Redirect Endpoint
|
|
273
|
-
* Creates a /mentra-auth endpoint that redirects to the MentraOS OAuth flow.
|
|
352
|
+
* Canonical v3 path is under the internal SDK namespace. The legacy
|
|
353
|
+
* `/api/mentra/auth` path remains as a compatibility alias during the
|
|
354
|
+
* transition so older Hono examples and early adopters keep working.
|
|
274
355
|
*/
|
|
275
|
-
private
|
|
356
|
+
private setupMentraWebviewAuth;
|
|
276
357
|
}
|
|
277
358
|
/**
|
|
278
359
|
* @deprecated Use `AppServerConfig` instead. `TpaServerConfig` is deprecated and will be removed in a future version.
|
|
279
360
|
* This is an alias for backward compatibility only.
|
|
280
|
-
*
|
|
281
|
-
* @example
|
|
282
|
-
* ```typescript
|
|
283
|
-
* // ❌ Deprecated - Don't use this
|
|
284
|
-
* const config: TpaServerConfig = { ... };
|
|
285
|
-
*
|
|
286
|
-
* // ✅ Use this instead
|
|
287
|
-
* const config: AppServerConfig = { ... };
|
|
288
|
-
* ```
|
|
289
361
|
*/
|
|
290
362
|
export type TpaServerConfig = AppServerConfig;
|
|
291
363
|
/**
|
|
292
364
|
* @deprecated Use `AppServer` instead. `TpaServer` is deprecated and will be removed in a future version.
|
|
293
365
|
* This is an alias for backward compatibility only.
|
|
294
|
-
*
|
|
295
|
-
* @example
|
|
296
|
-
* ```typescript
|
|
297
|
-
* // ❌ Deprecated - Don't use this
|
|
298
|
-
* class MyServer extends TpaServer { ... }
|
|
299
|
-
*
|
|
300
|
-
* // ✅ Use this instead
|
|
301
|
-
* class MyServer extends AppServer { ... }
|
|
302
|
-
* ```
|
|
303
366
|
*/
|
|
304
367
|
export declare class TpaServer extends AppServer {
|
|
305
368
|
constructor(config: TpaServerConfig);
|
|
306
369
|
}
|
|
370
|
+
export {};
|
|
307
371
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/app/server/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/app/server/index.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,KAAK,EAAE,OAAO,EAAqB,MAAM,MAAM,CAAC;AAEvD,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAI9B,OAAO,EAGL,qBAAq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AAO,CAAC;QAAE,SAAS,EAAE,aAAa,CAAA;KAAE,CAAC,GACvC,OAAO,CAAC,QAAQ,CAAC;IAmBpB;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IAgBxB;;;OAGG;IACH,OAAO,CAAC,qBAAqB;IA8D7B;;;OAGG;IACH,OAAO,CAAC,cAAc;IAQtB;;;;;;;;;;;;;;OAcG;IACH,OAAO,CAAC,aAAa;IA0BrB;;;;;;;;;;;;;;;OAeG;YACW,OAAO;IA6BrB;;;OAGG;IACH,OAAO,CAAC,wBAAwB;IA2FhC;;;OAGG;IACH,OAAO,CAAC,uBAAuB;IAW/B;;;;;;OAMG;IACH,OAAO,CAAC,sBAAsB;CAW/B;AAED;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,eAAe,CAAC;AAE9C;;;GAGG;AACH,qBAAa,SAAU,SAAQ,SAAS;gBAC1B,MAAM,EAAE,eAAe;CAQpC"}
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
* 🎮 Event Manager Module
|
|
3
3
|
*/
|
|
4
4
|
import EventEmitter from "events";
|
|
5
|
-
import {
|
|
5
|
+
import type { Logger } from "pino";
|
|
6
|
+
import { StreamType, ExtendedStreamType, AppSettings, WebSocketError, ButtonPress, HeadPosition, PhoneNotification, TranscriptionData, TranslationData, GlassesBatteryUpdate, PhoneBatteryUpdate, GlassesConnectionState, LocationUpdate, Vad, AudioChunk, CalendarEvent, VpsCoordinates, CustomMessage, StreamStatus, PhotoTaken, ManagedStreamStatus, PhoneNotificationDismissed, Capabilities, TouchEvent } from "../../types";
|
|
6
7
|
import { DashboardMode } from "../../types/dashboard";
|
|
7
8
|
import { PermissionErrorDetail } from "../../types/messages/cloud-to-app";
|
|
8
9
|
/** 🎯 Type-safe event handler function */
|
|
@@ -61,7 +62,7 @@ export interface StreamDataTypes {
|
|
|
61
62
|
[StreamType.PHONE_NOTIFICATION_DISMISSED]: PhoneNotificationDismissed;
|
|
62
63
|
[StreamType.AUDIO_CHUNK]: AudioChunk;
|
|
63
64
|
[StreamType.VIDEO]: ArrayBuffer;
|
|
64
|
-
[StreamType.
|
|
65
|
+
[StreamType.STREAM_STATUS]: StreamStatus;
|
|
65
66
|
[StreamType.MANAGED_STREAM_STATUS]: ManagedStreamStatus;
|
|
66
67
|
[StreamType.VPS_COORDINATES]: VpsCoordinates;
|
|
67
68
|
[StreamType.PHOTO_TAKEN]: PhotoTaken;
|
|
@@ -82,7 +83,8 @@ export declare class EventManager {
|
|
|
82
83
|
private handlers;
|
|
83
84
|
private lastLanguageTranscriptioCleanupHandler;
|
|
84
85
|
private lastLanguageTranslationCleanupHandler;
|
|
85
|
-
|
|
86
|
+
private logger;
|
|
87
|
+
constructor(subscribe: (type: ExtendedStreamType) => void, unsubscribe: (type: ExtendedStreamType) => void, packageName: string, baseUrl: string, logger: Logger);
|
|
86
88
|
onTranscription(handler: Handler<TranscriptionData>): () => void;
|
|
87
89
|
/**
|
|
88
90
|
* 🎤 Listen for transcription events in a specific language
|
|
@@ -187,6 +189,18 @@ export declare class EventManager {
|
|
|
187
189
|
* instead of being stored separately, preventing drift between the two.
|
|
188
190
|
*/
|
|
189
191
|
getRegisteredStreams(): ExtendedStreamType[];
|
|
192
|
+
/**
|
|
193
|
+
* 🔍 Find a registered stream that matches the incoming stream type.
|
|
194
|
+
*
|
|
195
|
+
* For non-language streams: exact match (existing behavior).
|
|
196
|
+
* For language streams: compare base type + transcribeLanguage
|
|
197
|
+
* (+ translateLanguage for translations), ignoring query params like ?hints=.
|
|
198
|
+
*
|
|
199
|
+
* This allows the SDK to receive data from a cloud stream whose subscription
|
|
200
|
+
* string doesn't include the same query params as the handler's subscription.
|
|
201
|
+
* For example, incoming "transcription:en-US" matches handler "transcription:en-US?hints=ja".
|
|
202
|
+
*/
|
|
203
|
+
findMatchingStream(incoming: ExtendedStreamType): ExtendedStreamType | null;
|
|
190
204
|
/**
|
|
191
205
|
* 📡 Emit an event to all registered handlers with error isolation
|
|
192
206
|
*/
|
|
@@ -196,6 +210,9 @@ export declare class EventManager {
|
|
|
196
210
|
* @param action - The action identifier to filter by
|
|
197
211
|
* @param handler - Function to handle the message
|
|
198
212
|
* @returns Cleanup function to remove the handler
|
|
213
|
+
* @deprecated Use settings.onMentraosChange() instead for system settings.
|
|
214
|
+
* This method was used for datetime updates but is no longer needed.
|
|
215
|
+
* Will be removed in a future version.
|
|
199
216
|
*/
|
|
200
217
|
onCustomMessage(action: string, handler: (payload: any) => void): () => void;
|
|
201
218
|
onVpsCoordinates(handler: Handler<VpsCoordinates>): () => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../../src/app/session/events.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,YAAY,MAAM,QAAQ,
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../../src/app/session/events.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,YAAY,MAAM,QAAQ,CAAC;AAClC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,EACL,UAAU,EACV,kBAAkB,EAClB,WAAW,EACX,cAAc,EAEd,WAAW,EACX,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EACf,oBAAoB,EACpB,kBAAkB,EAClB,sBAAsB,EACtB,cAAc,EACd,GAAG,EACH,UAAU,EACV,aAAa,EACb,cAAc,EAOd,aAAa,EACb,YAAY,EACZ,UAAU,EACV,mBAAmB,EACnB,0BAA0B,EAC1B,YAAY,EACZ,UAAU,EAEX,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAG1E,0CAA0C;AAC1C,KAAK,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAC;AAEpC,2CAA2C;AAC3C,UAAU,YAA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