@mentra/sdk 2.1.31-beta.5 → 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 +208 -70
- 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 +113 -93
- 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 +8957 -4428
- 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,14 +1,25 @@
|
|
|
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, PhotoData } from "../../types";
|
|
1
|
+
import { Hono } from "hono";
|
|
2
|
+
import type { Context } from "hono";
|
|
10
3
|
import { Logger } from "pino";
|
|
4
|
+
import { SessionWebhookRequest, StopWebhookRequest, ToolCall, AuthVariables } from "../../types";
|
|
5
|
+
import { AppSession } from "../session/index";
|
|
6
|
+
import type { PhotoData } from "../../types/photo-data";
|
|
11
7
|
export declare const GIVE_APP_CONTROL_OF_TOOL_RESPONSE: string;
|
|
8
|
+
/**
|
|
9
|
+
* Pending photo request stored at AppServer level for reconnection resilience.
|
|
10
|
+
* This allows O(1) lookup when photo uploads arrive via HTTP,
|
|
11
|
+
* and survives session reconnections.
|
|
12
|
+
* See: cloud/issues/019-sdk-photo-request-architecture
|
|
13
|
+
*/
|
|
14
|
+
interface PendingPhotoRequest {
|
|
15
|
+
userId: string;
|
|
16
|
+
sessionId: string;
|
|
17
|
+
session: AppSession;
|
|
18
|
+
resolve: (photo: PhotoData) => void;
|
|
19
|
+
reject: (error: Error) => void;
|
|
20
|
+
timestamp: number;
|
|
21
|
+
timeoutId?: ReturnType<typeof setTimeout>;
|
|
22
|
+
}
|
|
12
23
|
/**
|
|
13
24
|
* 🔧 Configuration options for App Server
|
|
14
25
|
*
|
|
@@ -47,27 +58,103 @@ export interface AppServerConfig {
|
|
|
47
58
|
cookieSecret?: string;
|
|
48
59
|
/** App instructions string shown to the user */
|
|
49
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";
|
|
50
81
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
82
|
+
type AppHono = Hono<{
|
|
83
|
+
Variables: AuthVariables;
|
|
84
|
+
}>;
|
|
85
|
+
/**
|
|
86
|
+
* 🎯 App Server Implementation
|
|
87
|
+
*
|
|
88
|
+
* Base class for creating App servers, now extending Hono for a modern API.
|
|
89
|
+
* Handles:
|
|
90
|
+
* - 🔄 Session lifecycle management
|
|
91
|
+
* - 📡 Webhook endpoints for MentraOS Cloud
|
|
92
|
+
* - 📂 Static file serving
|
|
93
|
+
* - ❤️ Health checks
|
|
94
|
+
* - 🧹 Cleanup on shutdown
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```typescript
|
|
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
|
+
*
|
|
106
|
+
* protected async onSession(session: AppSession, sessionId: string, userId: string) {
|
|
107
|
+
* // Handle new user sessions here
|
|
108
|
+
* session.events.onTranscription((data) => {
|
|
109
|
+
* session.layouts.showTextWall(data.text);
|
|
110
|
+
* });
|
|
111
|
+
* }
|
|
112
|
+
* }
|
|
113
|
+
*
|
|
114
|
+
* const server = new MyAppServer({
|
|
115
|
+
* packageName: 'org.example.myapp',
|
|
116
|
+
* apiKey: 'your_api_key',
|
|
117
|
+
* });
|
|
118
|
+
*
|
|
119
|
+
* await server.start();
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
export declare class AppServer extends Hono<{
|
|
123
|
+
Variables: AuthVariables;
|
|
124
|
+
}> {
|
|
125
|
+
/** Server configuration */
|
|
126
|
+
protected config: AppServerConfig;
|
|
55
127
|
/** Map of active user sessions by sessionId */
|
|
56
128
|
private activeSessions;
|
|
57
129
|
/** Map of active user sessions by userId */
|
|
58
130
|
private activeSessionsByUserId;
|
|
131
|
+
/** Guards against running cleanup twice (double Ctrl-C, SIGINT+SIGTERM, etc.) */
|
|
132
|
+
private _cleanupPromise;
|
|
133
|
+
/**
|
|
134
|
+
* Pending photo requests by requestId - owned by AppServer for HTTP endpoint access.
|
|
135
|
+
* This is the single source of truth for pending photo requests.
|
|
136
|
+
* Stored here (not on CameraModule) because:
|
|
137
|
+
* 1. Photo uploads arrive via HTTP to AppServer, not via WebSocket to session
|
|
138
|
+
* 2. Allows O(1) lookup by requestId instead of iterating all sessions
|
|
139
|
+
* 3. Survives session reconnections (session may be removed from activeSessions temporarily)
|
|
140
|
+
* See: cloud/issues/019-sdk-photo-request-architecture
|
|
141
|
+
*/
|
|
142
|
+
private pendingPhotoRequests;
|
|
59
143
|
/** Array of cleanup handlers to run on shutdown */
|
|
60
144
|
private cleanupHandlers;
|
|
61
145
|
/** App instructions string shown to the user */
|
|
62
146
|
private appInstructions;
|
|
63
|
-
/**
|
|
64
|
-
* Registry for photo requests that persists across session lifecycle.
|
|
65
|
-
* This fixes race conditions where sessions reconnect during photo capture.
|
|
66
|
-
*/
|
|
67
|
-
private photoRequestRegistry;
|
|
68
147
|
readonly logger: Logger;
|
|
69
148
|
constructor(config: AppServerConfig);
|
|
70
|
-
|
|
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;
|
|
71
158
|
/**
|
|
72
159
|
* 👥 Session Handler
|
|
73
160
|
* Override this method to handle new App sessions.
|
|
@@ -97,15 +184,37 @@ export declare class AppServer {
|
|
|
97
184
|
* @returns Optional string response that will be sent back to MentraOS Cloud
|
|
98
185
|
*/
|
|
99
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;
|
|
100
191
|
/**
|
|
101
|
-
* 🚀
|
|
102
|
-
*
|
|
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()
|
|
103
200
|
*
|
|
104
|
-
*
|
|
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
|
|
105
209
|
*/
|
|
106
210
|
start(): Promise<void>;
|
|
107
211
|
/**
|
|
108
|
-
*
|
|
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
|
|
109
218
|
* Gracefully shuts down the server and cleans up all sessions.
|
|
110
219
|
*/
|
|
111
220
|
stop(): Promise<void>;
|
|
@@ -120,54 +229,111 @@ export declare class AppServer {
|
|
|
120
229
|
*/
|
|
121
230
|
protected generateToken(userId: string, sessionId: string, secretKey: string): string;
|
|
122
231
|
/**
|
|
123
|
-
*
|
|
232
|
+
* Add Cleanup Handler
|
|
124
233
|
* Register a function to be called during server shutdown.
|
|
125
234
|
*
|
|
126
235
|
* @param handler - Function to call during cleanup
|
|
127
236
|
*/
|
|
128
237
|
protected addCleanupHandler(handler: () => void): void;
|
|
129
238
|
/**
|
|
130
|
-
*
|
|
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
|
|
131
271
|
* Creates the webhook endpoint that MentraOS Cloud calls to start new sessions.
|
|
132
272
|
*/
|
|
133
273
|
private setupWebhook;
|
|
134
274
|
/**
|
|
135
|
-
*
|
|
275
|
+
* Setup Tool Call Endpoint
|
|
136
276
|
* Creates a /tool endpoint for handling tool calls from MentraOS Cloud.
|
|
137
277
|
*/
|
|
138
278
|
private setupToolCallEndpoint;
|
|
139
279
|
/**
|
|
140
280
|
* Handle a session request webhook
|
|
141
281
|
*/
|
|
142
|
-
|
|
282
|
+
protected handleSessionWebhookRequest(request: SessionWebhookRequest, c: Context<{
|
|
283
|
+
Variables: AuthVariables;
|
|
284
|
+
}>): Promise<Response>;
|
|
143
285
|
/**
|
|
144
286
|
* Handle a stop request webhook
|
|
145
287
|
*/
|
|
146
|
-
|
|
288
|
+
protected handleStopWebhookRequest(request: StopWebhookRequest, c: Context<{
|
|
289
|
+
Variables: AuthVariables;
|
|
290
|
+
}>): Promise<Response>;
|
|
147
291
|
/**
|
|
148
|
-
*
|
|
292
|
+
* Setup Health Check Endpoint
|
|
149
293
|
* Creates a /health endpoint for monitoring server status.
|
|
150
294
|
*/
|
|
151
295
|
private setupHealthCheck;
|
|
152
296
|
/**
|
|
153
|
-
*
|
|
297
|
+
* Setup Settings Endpoint
|
|
154
298
|
* Creates a /settings endpoint that the MentraOS Cloud can use to update settings.
|
|
155
299
|
*/
|
|
156
300
|
private setupSettingsEndpoint;
|
|
157
301
|
/**
|
|
158
|
-
*
|
|
159
|
-
* Configures
|
|
302
|
+
* Setup Static File Serving
|
|
303
|
+
* Configures Hono to serve static files from the specified directory.
|
|
160
304
|
*/
|
|
161
305
|
private setupPublicDir;
|
|
162
306
|
/**
|
|
163
|
-
*
|
|
164
|
-
*
|
|
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
|
|
165
320
|
*/
|
|
166
321
|
private setupShutdown;
|
|
167
322
|
/**
|
|
168
323
|
* 🧹 Cleanup
|
|
169
324
|
* Closes all active sessions and runs cleanup handlers.
|
|
170
|
-
*
|
|
325
|
+
* Does NOT release ownership - we want the cloud to resurrect when we come back up.
|
|
326
|
+
*
|
|
327
|
+
* OWNERSHIP_RELEASE should only be sent for:
|
|
328
|
+
* - switching_clouds: User moved to another cloud, don't compete
|
|
329
|
+
* - user_logout: User explicitly logged out
|
|
330
|
+
*
|
|
331
|
+
* NOT for clean_shutdown, because:
|
|
332
|
+
* - Server is restarting/redeploying
|
|
333
|
+
* - Cloud should resurrect the app (trigger webhook)
|
|
334
|
+
* - User expects their app to keep running
|
|
335
|
+
*
|
|
336
|
+
* See: cloud/issues/023-disposed-appsession-resurrection-bug
|
|
171
337
|
*/
|
|
172
338
|
private cleanup;
|
|
173
339
|
/**
|
|
@@ -176,58 +342,30 @@ export declare class AppServer {
|
|
|
176
342
|
*/
|
|
177
343
|
private setupPhotoUploadEndpoint;
|
|
178
344
|
/**
|
|
179
|
-
*
|
|
345
|
+
* Setup Mentra Auth Redirect Endpoint
|
|
180
346
|
* Creates a /mentra-auth endpoint that redirects to the MentraOS OAuth flow.
|
|
181
347
|
*/
|
|
182
348
|
private setupMentraAuthRedirect;
|
|
183
349
|
/**
|
|
184
|
-
*
|
|
185
|
-
*/
|
|
186
|
-
private findSessionByPhotoRequestId;
|
|
187
|
-
/**
|
|
188
|
-
* Register a photo request at the AppServer level.
|
|
189
|
-
* This persists the request across session reconnections so photos can be
|
|
190
|
-
* delivered even if the user's session disconnects and reconnects.
|
|
350
|
+
* Setup SDK-owned webview auth routes.
|
|
191
351
|
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
* @param reject - Promise reject function to call on error/timeout
|
|
196
|
-
*/
|
|
197
|
-
registerPhotoRequest(requestId: string, userId: string, resolve: (photoData: PhotoData) => void, reject: (reason: string) => void): void;
|
|
198
|
-
/**
|
|
199
|
-
* Unregister a photo request (called when request is fulfilled or cancelled)
|
|
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.
|
|
200
355
|
*/
|
|
201
|
-
|
|
356
|
+
private setupMentraWebviewAuth;
|
|
202
357
|
}
|
|
203
358
|
/**
|
|
204
359
|
* @deprecated Use `AppServerConfig` instead. `TpaServerConfig` is deprecated and will be removed in a future version.
|
|
205
360
|
* This is an alias for backward compatibility only.
|
|
206
|
-
*
|
|
207
|
-
* @example
|
|
208
|
-
* ```typescript
|
|
209
|
-
* // ❌ Deprecated - Don't use this
|
|
210
|
-
* const config: TpaServerConfig = { ... };
|
|
211
|
-
*
|
|
212
|
-
* // ✅ Use this instead
|
|
213
|
-
* const config: AppServerConfig = { ... };
|
|
214
|
-
* ```
|
|
215
361
|
*/
|
|
216
362
|
export type TpaServerConfig = AppServerConfig;
|
|
217
363
|
/**
|
|
218
364
|
* @deprecated Use `AppServer` instead. `TpaServer` is deprecated and will be removed in a future version.
|
|
219
365
|
* This is an alias for backward compatibility only.
|
|
220
|
-
*
|
|
221
|
-
* @example
|
|
222
|
-
* ```typescript
|
|
223
|
-
* // ❌ Deprecated - Don't use this
|
|
224
|
-
* class MyServer extends TpaServer { ... }
|
|
225
|
-
*
|
|
226
|
-
* // ✅ Use this instead
|
|
227
|
-
* class MyServer extends AppServer { ... }
|
|
228
|
-
* ```
|
|
229
366
|
*/
|
|
230
367
|
export declare class TpaServer extends AppServer {
|
|
231
368
|
constructor(config: TpaServerConfig);
|
|
232
369
|
}
|
|
370
|
+
export {};
|
|
233
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,qBAAqB,EACrB,kBAAkB,EAClB,QAAQ,EAER,aAAa,EACd,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAI9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAExD,eAAO,MAAM,iCAAiC,EAAE,MAA4C,CAAC;AAI7F;;;;;GAKG;AACH,UAAU,mBAAmB;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,UAAU,CAAC;IACpB,OAAO,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,CAAC;IACpC,MAAM,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC;CAC3C;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,eAAe;IAC9B,oIAAoI;IACpI,WAAW,EAAE,MAAM,CAAC;IACpB,wDAAwD;IACxD,MAAM,EAAE,MAAM,CAAC;IACf,oDAAoD;IACpD,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,kDAAkD;IAClD,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,+FAA+F;IAC/F,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IAE3B,iEAAiE;IACjE,WAAW,CAA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C,YAAY;IA2CpB;;;OAGG;IACH,OAAO,CAAC,qBAAqB;IAsC7B;;OAEG;cACa,2BAA2B,CACzC,OAAO,EAAE,qBAAqB,EAC9B,CAAC,EAAE,OAAO,CAAC;QAAE,SAAS,EAAE,aAAa,CAAA;KAAE,CAAC,GACvC,OAAO,CAAC,QAAQ,CAAC;IAsJpB;;OAEG;cACa,wBAAwB,CACtC,OAAO,EAAE,kBAAkB,EAC3B,CAAC,EAAE,OAAO,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,0B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