@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.
Files changed (169) hide show
  1. package/README.md +54 -9
  2. package/dist/MiniAppServer.d.ts +58 -0
  3. package/dist/MiniAppServer.d.ts.map +1 -0
  4. package/dist/app/server/index.d.ts +208 -70
  5. package/dist/app/server/index.d.ts.map +1 -1
  6. package/dist/app/session/events.d.ts +20 -3
  7. package/dist/app/session/events.d.ts.map +1 -1
  8. package/dist/app/session/index.d.ts +56 -3
  9. package/dist/app/session/index.d.ts.map +1 -1
  10. package/dist/app/session/modules/audio-output-stream.d.ts +108 -0
  11. package/dist/app/session/modules/audio-output-stream.d.ts.map +1 -0
  12. package/dist/app/session/modules/audio.d.ts +36 -1
  13. package/dist/app/session/modules/audio.d.ts.map +1 -1
  14. package/dist/app/session/modules/camera-managed-extension.d.ts +37 -33
  15. package/dist/app/session/modules/camera-managed-extension.d.ts.map +1 -1
  16. package/dist/app/session/modules/camera.d.ts +113 -93
  17. package/dist/app/session/modules/camera.d.ts.map +1 -1
  18. package/dist/app/session/modules/index.d.ts +4 -3
  19. package/dist/app/session/modules/index.d.ts.map +1 -1
  20. package/dist/app/session/modules/led.d.ts.map +1 -1
  21. package/dist/app/session/modules/location.d.ts.map +1 -1
  22. package/dist/app/session/settings.d.ts +5 -1
  23. package/dist/app/session/settings.d.ts.map +1 -1
  24. package/dist/app/webview/index.d.ts +67 -9
  25. package/dist/app/webview/index.d.ts.map +1 -1
  26. package/dist/constants/log-messages/updates.d.ts +32 -9
  27. package/dist/constants/log-messages/updates.d.ts.map +1 -1
  28. package/dist/constants/log-messages/warning.d.ts +12 -0
  29. package/dist/constants/log-messages/warning.d.ts.map +1 -1
  30. package/dist/display-utils.d.ts +3 -1
  31. package/dist/display-utils.d.ts.map +1 -1
  32. package/dist/display-utils.js +443 -26
  33. package/dist/display-utils.js.map +10 -6
  34. package/dist/index.d.ts +22 -14
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +8957 -4428
  37. package/dist/index.js.map +63 -31
  38. package/dist/internal/_SessionManager.d.ts +76 -0
  39. package/dist/internal/_SessionManager.d.ts.map +1 -0
  40. package/dist/logging/clean-transport.d.ts +50 -0
  41. package/dist/logging/clean-transport.d.ts.map +1 -0
  42. package/dist/logging/errors.d.ts +90 -0
  43. package/dist/logging/errors.d.ts.map +1 -0
  44. package/dist/logging/logger.d.ts +72 -1
  45. package/dist/logging/logger.d.ts.map +1 -1
  46. package/dist/logging/telemetry-transport.d.ts +51 -0
  47. package/dist/logging/telemetry-transport.d.ts.map +1 -0
  48. package/dist/session/DataStreamRouter.d.ts +219 -0
  49. package/dist/session/DataStreamRouter.d.ts.map +1 -0
  50. package/dist/session/MentraSession.d.ts +102 -0
  51. package/dist/session/MentraSession.d.ts.map +1 -0
  52. package/dist/session/index.d.ts +2 -0
  53. package/dist/session/index.d.ts.map +1 -0
  54. package/dist/session/internal/_ConnectionManager.d.ts +43 -0
  55. package/dist/session/internal/_ConnectionManager.d.ts.map +1 -0
  56. package/dist/session/internal/_MessageRouter.d.ts +11 -0
  57. package/dist/session/internal/_MessageRouter.d.ts.map +1 -0
  58. package/dist/session/internal/_SubscriptionManager.d.ts +32 -0
  59. package/dist/session/internal/_SubscriptionManager.d.ts.map +1 -0
  60. package/dist/session/internal/_V2AudioStreamShim.d.ts +12 -0
  61. package/dist/session/internal/_V2AudioStreamShim.d.ts.map +1 -0
  62. package/dist/session/internal/_V2CameraShim.d.ts +52 -0
  63. package/dist/session/internal/_V2CameraShim.d.ts.map +1 -0
  64. package/dist/session/internal/_V2EventManagerShim.d.ts +52 -0
  65. package/dist/session/internal/_V2EventManagerShim.d.ts.map +1 -0
  66. package/dist/session/internal/_V2SessionShim.d.ts +169 -0
  67. package/dist/session/internal/_V2SessionShim.d.ts.map +1 -0
  68. package/dist/session/internal/_V2SettingsShim.d.ts +17 -0
  69. package/dist/session/internal/_V2SettingsShim.d.ts.map +1 -0
  70. package/dist/session/managers/CameraManager.d.ts +198 -0
  71. package/dist/session/managers/CameraManager.d.ts.map +1 -0
  72. package/dist/session/managers/DashboardManager.d.ts +131 -0
  73. package/dist/session/managers/DashboardManager.d.ts.map +1 -0
  74. package/dist/session/managers/DeviceManager.d.ts +348 -0
  75. package/dist/session/managers/DeviceManager.d.ts.map +1 -0
  76. package/dist/session/managers/DisplayManager.d.ts +171 -0
  77. package/dist/session/managers/DisplayManager.d.ts.map +1 -0
  78. package/dist/session/managers/LedManager.d.ts +116 -0
  79. package/dist/session/managers/LedManager.d.ts.map +1 -0
  80. package/dist/session/managers/LocationManager.d.ts +224 -0
  81. package/dist/session/managers/LocationManager.d.ts.map +1 -0
  82. package/dist/session/managers/MicManager.d.ts +252 -0
  83. package/dist/session/managers/MicManager.d.ts.map +1 -0
  84. package/dist/session/managers/PermissionsManager.d.ts +139 -0
  85. package/dist/session/managers/PermissionsManager.d.ts.map +1 -0
  86. package/dist/session/managers/PhoneManager.d.ts +351 -0
  87. package/dist/session/managers/PhoneManager.d.ts.map +1 -0
  88. package/dist/session/managers/SpeakerManager.d.ts +285 -0
  89. package/dist/session/managers/SpeakerManager.d.ts.map +1 -0
  90. package/dist/session/managers/StorageManager.d.ts +289 -0
  91. package/dist/session/managers/StorageManager.d.ts.map +1 -0
  92. package/dist/session/managers/TimeUtils.d.ts +175 -0
  93. package/dist/session/managers/TimeUtils.d.ts.map +1 -0
  94. package/dist/session/managers/TranscriptionManager.d.ts +195 -0
  95. package/dist/session/managers/TranscriptionManager.d.ts.map +1 -0
  96. package/dist/session/managers/TranslationManager.d.ts +189 -0
  97. package/dist/session/managers/TranslationManager.d.ts.map +1 -0
  98. package/dist/session.d.ts +41 -0
  99. package/dist/session.d.ts.map +1 -0
  100. package/dist/session.js +4110 -0
  101. package/dist/session.js.map +44 -0
  102. package/dist/transport/Transport.d.ts +119 -0
  103. package/dist/transport/Transport.d.ts.map +1 -0
  104. package/dist/transport/WebSocketTransport.d.ts +73 -0
  105. package/dist/transport/WebSocketTransport.d.ts.map +1 -0
  106. package/dist/types/index.d.ts +31 -5
  107. package/dist/types/index.d.ts.map +1 -1
  108. package/dist/types/message-types.d.ts +25 -9
  109. package/dist/types/message-types.d.ts.map +1 -1
  110. package/dist/types/messages/app-to-cloud.d.ts +113 -16
  111. package/dist/types/messages/app-to-cloud.d.ts.map +1 -1
  112. package/dist/types/messages/cloud-to-app.d.ts +50 -4
  113. package/dist/types/messages/cloud-to-app.d.ts.map +1 -1
  114. package/dist/types/messages/cloud-to-glasses.d.ts +43 -14
  115. package/dist/types/messages/cloud-to-glasses.d.ts.map +1 -1
  116. package/dist/types/messages/glasses-to-cloud.d.ts +5 -5
  117. package/dist/types/messages/glasses-to-cloud.d.ts.map +1 -1
  118. package/dist/types/models.d.ts +17 -0
  119. package/dist/types/models.d.ts.map +1 -1
  120. package/dist/types/rtmp-stream.d.ts +4 -4
  121. package/dist/types/rtmp-stream.d.ts.map +1 -1
  122. package/dist/types/streams.d.ts +6 -1
  123. package/dist/types/streams.d.ts.map +1 -1
  124. package/dist/types/webhooks.d.ts +11 -0
  125. package/dist/types/webhooks.d.ts.map +1 -1
  126. package/dist/utils/error-utils.d.ts +139 -0
  127. package/dist/utils/error-utils.d.ts.map +1 -0
  128. package/dist/utils/permissions-utils.d.ts +30 -7
  129. package/dist/utils/permissions-utils.d.ts.map +1 -1
  130. package/node_modules/@mentra/types/dist/applet.d.ts +5 -1
  131. package/node_modules/@mentra/types/dist/applet.d.ts.map +1 -1
  132. package/node_modules/@mentra/types/dist/capabilities/even-realities-g2.d.ts +12 -0
  133. package/node_modules/@mentra/types/dist/capabilities/even-realities-g2.d.ts.map +1 -0
  134. package/node_modules/@mentra/types/dist/capabilities/even-realities-g2.js +61 -0
  135. package/node_modules/@mentra/types/dist/capabilities/mentra-display.d.ts +12 -0
  136. package/node_modules/@mentra/types/dist/capabilities/mentra-display.d.ts.map +1 -0
  137. package/node_modules/@mentra/types/dist/capabilities/mentra-display.js +54 -0
  138. package/node_modules/@mentra/types/dist/capabilities/none.d.ts +13 -0
  139. package/node_modules/@mentra/types/dist/capabilities/none.d.ts.map +1 -0
  140. package/node_modules/@mentra/types/dist/capabilities/none.js +67 -0
  141. package/node_modules/@mentra/types/dist/enums.d.ts +8 -2
  142. package/node_modules/@mentra/types/dist/enums.d.ts.map +1 -1
  143. package/node_modules/@mentra/types/dist/enums.js +9 -2
  144. package/node_modules/@mentra/types/dist/hardware.d.ts +3 -1
  145. package/node_modules/@mentra/types/dist/hardware.d.ts.map +1 -1
  146. package/node_modules/@mentra/types/dist/hardware.js +12 -2
  147. package/node_modules/@mentra/types/dist/index.d.ts +1 -1
  148. package/node_modules/@mentra/types/dist/index.d.ts.map +1 -1
  149. package/node_modules/@mentra/types/dist/index.js +2 -1
  150. package/node_modules/@mentra/types/package.json +2 -2
  151. package/package.json +24 -12
  152. package/dist/examples/managed-rtmp-streaming-example.d.ts +0 -2
  153. package/dist/examples/managed-rtmp-streaming-example.d.ts.map +0 -1
  154. package/dist/examples/managed-rtmp-streaming-with-restream-example.d.ts +0 -11
  155. package/dist/examples/managed-rtmp-streaming-with-restream-example.d.ts.map +0 -1
  156. package/dist/examples/rtmp-streaming-example.d.ts +0 -2
  157. package/dist/examples/rtmp-streaming-example.d.ts.map +0 -1
  158. package/node_modules/@mentra/types/src/applet.ts +0 -51
  159. package/node_modules/@mentra/types/src/capabilities/even-realities-g1.ts +0 -63
  160. package/node_modules/@mentra/types/src/capabilities/mentra-live.ts +0 -103
  161. package/node_modules/@mentra/types/src/capabilities/simulated-glasses.ts +0 -76
  162. package/node_modules/@mentra/types/src/capabilities/vuzix-z100.ts +0 -60
  163. package/node_modules/@mentra/types/src/cli.ts +0 -169
  164. package/node_modules/@mentra/types/src/device.ts +0 -43
  165. package/node_modules/@mentra/types/src/enums.ts +0 -36
  166. package/node_modules/@mentra/types/src/hardware.ts +0 -172
  167. package/node_modules/@mentra/types/src/index.ts +0 -64
  168. package/node_modules/@mentra/types/tsconfig.json +0 -22
  169. package/node_modules/@mentra/types/tsconfig.tsbuildinfo +0 -1
@@ -0,0 +1,76 @@
1
+ /**
2
+ * _SessionManager
3
+ *
4
+ * Consolidated server-level session orchestrator. Merges the responsibilities
5
+ * of the previous four separate classes into one:
6
+ *
7
+ * _MentraSessionServerFactory → createSession()
8
+ * _MiniAppSessionRegistry → session tracking (bySessionId, byUserId maps)
9
+ * _MiniAppServerCallbackBridge → callback storage (onSession, onStop, onToolCall)
10
+ * _MiniAppServerRuntime → webhook handling (handleSessionRequest, handleStopRequest)
11
+ *
12
+ * This is an internal class — never exported to developers.
13
+ * MiniAppServer is the only consumer.
14
+ *
15
+ * See decisions.md D-007 for rationale on the consolidation.
16
+ *
17
+ * @internal
18
+ */
19
+ import type { Logger } from "pino";
20
+ import type { WebhookResponse, SessionWebhookRequest, StopWebhookRequest, ToolCall } from "../types";
21
+ import type { MentraSessionConfig } from "../session";
22
+ import { MentraSession } from "../session";
23
+ import { _V2SessionShim } from "../session/internal/_V2SessionShim";
24
+ import type { _V2PhotoRequestBridge } from "../session/internal/_V2CameraShim";
25
+ export interface _SessionManagerConfig {
26
+ packageName: string;
27
+ apiKey: string;
28
+ logger: Logger;
29
+ serverUrl?: string;
30
+ logLevel?: MentraSessionConfig["logLevel"];
31
+ verbose?: MentraSessionConfig["verbose"];
32
+ photoRequestBridge?: _V2PhotoRequestBridge;
33
+ }
34
+ export type _SessionHandler = (session: _V2SessionShim) => void | Promise<void>;
35
+ export type _StopHandler = (session: _V2SessionShim | null, reason: string) => void | Promise<void>;
36
+ export type _ToolCallHandler = (toolCall: ToolCall) => string | undefined | Promise<string | undefined>;
37
+ interface SessionRecord {
38
+ session: MentraSession;
39
+ compatSession: _V2SessionShim;
40
+ userId: string;
41
+ sessionId: string;
42
+ }
43
+ export declare class _SessionManager {
44
+ private readonly config;
45
+ private readonly logger;
46
+ private readonly bySessionId;
47
+ private readonly byUserId;
48
+ private sessionHandler?;
49
+ private stopHandler?;
50
+ private toolCallHandler?;
51
+ private readonly callbackSessionCache;
52
+ private readonly stopSuppression;
53
+ constructor(config: _SessionManagerConfig);
54
+ onSession(handler: _SessionHandler): void;
55
+ onStop(handler: _StopHandler): void;
56
+ onToolCall(handler: _ToolCallHandler): void;
57
+ getBySessionId(sessionId: string): SessionRecord | null;
58
+ getByUserId(userId: string): SessionRecord | null;
59
+ get size(): number;
60
+ handleSessionRequest(request: SessionWebhookRequest): Promise<WebhookResponse>;
61
+ handleStopRequest(request: StopWebhookRequest): Promise<WebhookResponse>;
62
+ handleToolCall(toolCall: ToolCall): Promise<{
63
+ status: "success";
64
+ reply: string | null;
65
+ }>;
66
+ shutdown(): Promise<void>;
67
+ private createSession;
68
+ private registrySet;
69
+ private registryDeleteBySessionId;
70
+ private deleteIfSameSession;
71
+ private invokeSessionHandler;
72
+ private invokeStopHandler;
73
+ private invokeToolCallHandler;
74
+ }
75
+ export {};
76
+ //# sourceMappingURL=_SessionManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_SessionManager.d.ts","sourceRoot":"","sources":["../../src/internal/_SessionManager.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Clean Transport for MentraOS SDK
3
+ *
4
+ * A lightweight pino-compatible writable stream that formats log output as
5
+ * single-line colored messages. This is the default console transport.
6
+ *
7
+ * Output format:
8
+ * MentraOS ✓ App server running on port 7010
9
+ * MentraOS ⚠ Connection lost, reconnecting (2/3)...
10
+ * MentraOS ✗ Invalid API key
11
+ *
12
+ * Color scheme:
13
+ * - "MentraOS" prefix: dim gray (always present, visually skippable)
14
+ * - ✓ (info): green — success events
15
+ * - ⚠ (warn): yellow — warnings, reconnecting, deprecations
16
+ * - ✗ (error/fatal): red — failures requiring action
17
+ * - · (debug/trace): dim — internal details (only visible at debug level)
18
+ * - Message text: default terminal color
19
+ *
20
+ * SDK internal log filtering:
21
+ * Logs tagged with `_sdk: true` (from managers and internal subsystems) are
22
+ * only shown in the terminal at warn level and above. This keeps the developer's
23
+ * terminal clean — their own `session.logger.info(...)` calls always show,
24
+ * while internal SDK chatter (subscription updates, ping, handler registration)
25
+ * is hidden unless the developer sets MENTRA_VERBOSE=true.
26
+ *
27
+ * BetterStack always receives ALL logs regardless of the _sdk tag — the
28
+ * filtering only applies to the terminal/clean transport.
29
+ *
30
+ * All structured context fields (app, packageName, service, userId, err, etc.)
31
+ * are intentionally hidden — they're only visible in verbose mode or in BetterStack.
32
+ * The `msg` field is the only thing shown to the developer.
33
+ */
34
+ import { Writable } from "stream";
35
+ /**
36
+ * Creates a writable stream that formats pino JSON log lines as single-line
37
+ * colored terminal output.
38
+ *
39
+ * Pino writes newline-delimited JSON to this stream. Each line is parsed,
40
+ * and only the `level` and `msg` fields are used for formatting. Everything
41
+ * else (structured context, error objects, timestamps) is ignored — those
42
+ * fields still flow to BetterStack via the separate @logtail/pino transport.
43
+ *
44
+ * Output is written to `process.stderr` by convention (keeps stdout clean
45
+ * for program output if someone pipes it).
46
+ *
47
+ * @returns A Node.js Writable stream compatible with pino's multistream.
48
+ */
49
+ export declare function createCleanStream(): Writable;
50
+ //# sourceMappingURL=clean-transport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clean-transport.d.ts","sourceRoot":"","sources":["../../src/logging/clean-transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AA0BlC;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,IAAI,QAAQ,CA6C5C"}
@@ -0,0 +1,90 @@
1
+ /**
2
+ * MentraOS SDK Error Classes
3
+ *
4
+ * Structured error hierarchy for programmatic error handling.
5
+ * All classes extend Error so `instanceof Error` checks still work (backward compatible).
6
+ *
7
+ * Usage:
8
+ * ```typescript
9
+ * import { MentraAuthError, MentraConnectionError } from '@mentra/sdk';
10
+ *
11
+ * session.events.onError((error) => {
12
+ * if (error instanceof MentraAuthError) {
13
+ * console.log('Bad API key, check your config');
14
+ * } else if (error instanceof MentraConnectionError) {
15
+ * console.log('Connection issue, will retry');
16
+ * }
17
+ * });
18
+ * ```
19
+ */
20
+ /**
21
+ * Base error class for all MentraOS SDK errors.
22
+ *
23
+ * Every SDK error has a `.code` string for programmatic matching
24
+ * without relying on `.message` string parsing.
25
+ */
26
+ export declare class MentraError extends Error {
27
+ readonly code: string;
28
+ constructor(message: string, code: string);
29
+ }
30
+ /**
31
+ * Authentication or authorization failure.
32
+ *
33
+ * Thrown/emitted when:
34
+ * - API key is invalid or expired
35
+ * - Token verification fails
36
+ * - Cloud rejects credentials
37
+ */
38
+ export declare class MentraAuthError extends MentraError {
39
+ constructor(message: string);
40
+ }
41
+ /**
42
+ * Connection-level failure.
43
+ *
44
+ * Thrown/emitted when:
45
+ * - WebSocket connection is refused (ECONNREFUSED)
46
+ * - Connection is lost unexpectedly
47
+ * - All reconnection attempts are exhausted
48
+ * - Server is unreachable
49
+ */
50
+ export declare class MentraConnectionError extends MentraError {
51
+ constructor(message: string, code?: string);
52
+ }
53
+ /**
54
+ * Operation timed out.
55
+ *
56
+ * Thrown/emitted when:
57
+ * - WebSocket connection handshake exceeds timeout
58
+ * - Photo request times out
59
+ * - Audio play request times out
60
+ */
61
+ export declare class MentraTimeoutError extends MentraError {
62
+ constructor(message: string);
63
+ }
64
+ /**
65
+ * Configuration or input validation failure.
66
+ *
67
+ * Thrown synchronously when:
68
+ * - WebSocket URL is missing or malformed
69
+ * - Layout is missing required properties
70
+ * - Invalid language code is provided
71
+ * - Required config fields are absent
72
+ */
73
+ export declare class MentraValidationError extends MentraError {
74
+ constructor(message: string);
75
+ }
76
+ /**
77
+ * Permission denied by MentraOS Cloud.
78
+ *
79
+ * Emitted when:
80
+ * - App subscribes to a stream it lacks permission for
81
+ * - Cloud rejects a subscription request
82
+ *
83
+ * Includes the stream name and required permission for programmatic handling.
84
+ */
85
+ export declare class MentraPermissionError extends MentraError {
86
+ readonly stream: string;
87
+ readonly requiredPermission: string;
88
+ constructor(message: string, stream: string, requiredPermission: string);
89
+ }
90
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/logging/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH;;;;;GAKG;AACH,qBAAa,WAAY,SAAQ,KAAK;aAGlB,IAAI,EAAE,MAAM;gBAD5B,OAAO,EAAE,MAAM,EACC,IAAI,EAAE,MAAM;CAS/B;AAED;;;;;;;GAOG;AACH,qBAAa,eAAgB,SAAQ,WAAW;gBAClC,OAAO,EAAE,MAAM;CAI5B;AAED;;;;;;;;GAQG;AACH,qBAAa,qBAAsB,SAAQ,WAAW;gBACxC,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,MAA2B;CAI/D;AAED;;;;;;;GAOG;AACH,qBAAa,kBAAmB,SAAQ,WAAW;gBACrC,OAAO,EAAE,MAAM;CAI5B;AAED;;;;;;;;GAQG;AACH,qBAAa,qBAAsB,SAAQ,WAAW;gBACxC,OAAO,EAAE,MAAM;CAI5B;AAED;;;;;;;;GAQG;AACH,qBAAa,qBAAsB,SAAQ,WAAW;aAGlC,MAAM,EAAE,MAAM;aACd,kBAAkB,EAAE,MAAM;gBAF1C,OAAO,EAAE,MAAM,EACC,MAAM,EAAE,MAAM,EACd,kBAAkB,EAAE,MAAM;CAK7C"}
@@ -1,4 +1,75 @@
1
+ /**
2
+ * MentraOS SDK Logger
3
+ *
4
+ * Factory-based logger that supports two modes:
5
+ *
6
+ * **Clean mode** (default): Single-line colored output via the clean transport.
7
+ * MentraOS ✓ App server running on port 7010
8
+ * MentraOS ✗ Invalid API key
9
+ *
10
+ * **Verbose mode**: Full pino-pretty structured output (today's behavior).
11
+ * Activated via `verbose: true` in config or `MENTRA_VERBOSE=true` env var.
12
+ *
13
+ * The BetterStack transport always runs at debug level when BETTERSTACK_SOURCE_TOKEN
14
+ * is set, regardless of the console transport level. This is intentional — it's
15
+ * an undocumented internal feature for Mentra's own apps.
16
+ *
17
+ * Resolution order for log level:
18
+ * 1. MENTRA_VERBOSE=true → verbose mode, debug level
19
+ * 2. MENTRA_LOG_LEVEL env var → sets level (debug implies verbose)
20
+ * 3. config.verbose: true → verbose mode, debug level
21
+ * 4. config.logLevel → sets level
22
+ * 5. Default → info level, clean mode
23
+ */
1
24
  import pino from "pino";
2
- export declare const logger: pino.Logger<never, boolean>;
25
+ import type { Logger } from "pino";
26
+ export type MentraLogLevel = "none" | "error" | "warn" | "info" | "debug";
27
+ export interface LoggerConfig {
28
+ /**
29
+ * SDK console log level. Default: 'info'.
30
+ * - 'none': Suppress all SDK console output
31
+ * - 'error': Only errors
32
+ * - 'warn': Errors + warnings
33
+ * - 'info': Errors + warnings + lifecycle events (default)
34
+ * - 'debug': Everything (verbose structured output)
35
+ *
36
+ * Can be overridden with MENTRA_LOG_LEVEL env var.
37
+ */
38
+ logLevel?: MentraLogLevel;
39
+ /**
40
+ * Enable verbose internal logging (full pino-pretty structured output).
41
+ * Useful when debugging SDK issues — Mentra support may ask you to enable this.
42
+ * Can also be enabled with MENTRA_VERBOSE=true env var.
43
+ * Default: false
44
+ */
45
+ verbose?: boolean;
46
+ }
47
+ /**
48
+ * Create a configured pino Logger instance.
49
+ *
50
+ * This is the primary entry point. Each AppServer creates one root logger
51
+ * via this function and then derives child loggers for sessions and modules.
52
+ *
53
+ * @param config - Optional logging configuration. If omitted, defaults to
54
+ * warn-level clean output (env vars can still override).
55
+ * @returns A pino Logger instance with the appropriate transports.
56
+ *
57
+ * @example
58
+ * ```typescript
59
+ * // Default: clean output at warn level
60
+ * const logger = createLogger();
61
+ *
62
+ * // Verbose for debugging
63
+ * const logger = createLogger({ verbose: true });
64
+ *
65
+ * // Quiet — errors only
66
+ * const logger = createLogger({ logLevel: 'error' });
67
+ *
68
+ * // Silent — suppress all console output (BetterStack still receives logs)
69
+ * const logger = createLogger({ logLevel: 'none' });
70
+ * ```
71
+ */
72
+ export declare function createLogger(config?: LoggerConfig): Logger;
73
+ export declare const logger: pino.Logger;
3
74
  export default logger;
4
75
  //# sourceMappingURL=logger.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logging/logger.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAA;AA+EvB,eAAO,MAAM,MAAM,6BAAuC,CAAA;AAS1D,eAAe,MAAM,CAAA"}
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logging/logger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,EAAE,MAAM,EAAS,MAAM,MAAM,CAAC;AAM1C,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAE1E,MAAM,WAAW,YAAY;IAC3B;;;;;;;;;OASG;IACH,QAAQ,CAAC,EAAE,cAAc,CAAC;IAE1B;;;;;OAKG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAgHD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,YAAY,CAAC,MAAM,CAAC,EAAE,YAAY,GAAG,MAAM,CA6D1D;AAWD,eAAO,MAAM,MAAM,aAGjB,CAAC;AAEH,eAAe,MAAM,CAAC"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Telemetry Transport for MentraOS SDK
3
+ *
4
+ * A pino-compatible Writable stream that intercepts log entries and pushes
5
+ * them into a session-scoped ring buffer for incident debugging.
6
+ *
7
+ * This transport is added to the session logger (not the server logger), so
8
+ * the buffer is automatically scoped to one user's session. Every log line
9
+ * written via session.logger — including all module child loggers (camera,
10
+ * audio, led, etc.) — is captured here with zero effort from app developers.
11
+ *
12
+ * Design notes:
13
+ * - Only captures info+ entries. Debug is too noisy for incident bundles;
14
+ * BetterStack captures debug separately.
15
+ * - Ring buffer: oldest entries are dropped when full. This is intentional —
16
+ * the most recent logs before a bug report are the most useful.
17
+ * - The buffer is an external array passed in by reference, so AppSession
18
+ * owns the lifetime and can clear it on disconnect simply by reassigning.
19
+ * - This transport does NOT forward to BetterStack or console — those run
20
+ * via the parent appServer.logger streams independently.
21
+ */
22
+ import { Writable } from "stream";
23
+ import type { TelemetryLogEntry } from "../types/messages/app-to-cloud";
24
+ /**
25
+ * Creates a pino-compatible Writable stream that pushes log entries into
26
+ * a caller-owned ring buffer.
27
+ *
28
+ * @param buffer - The array to push entries into. Owned by the caller
29
+ * (AppSession). Passed by reference so the caller can
30
+ * clear it by splicing or reassigning.
31
+ * @param bufferSize - Maximum number of entries to keep. When the buffer
32
+ * exceeds this, the oldest entries are dropped.
33
+ * Default: 500.
34
+ * @returns A Node.js Writable stream compatible with pino's multistream.
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * const telemetryBuffer: TelemetryLogEntry[] = []
39
+ * const stream = createTelemetryStream(telemetryBuffer, 500)
40
+ *
41
+ * const logger = pino(
42
+ * { level: "debug" },
43
+ * pino.multistream([
44
+ * { stream: parentStream, level: "warn" },
45
+ * { stream: stream, level: "info" },
46
+ * ])
47
+ * )
48
+ * ```
49
+ */
50
+ export declare function createTelemetryStream(buffer: TelemetryLogEntry[], bufferSize?: number): Writable;
51
+ //# sourceMappingURL=telemetry-transport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telemetry-transport.d.ts","sourceRoot":"","sources":["../../src/logging/telemetry-transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAClC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAiBxE;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,iBAAiB,EAAE,EAAE,UAAU,SAAM,GAAG,QAAQ,CAwD7F"}
@@ -0,0 +1,219 @@
1
+ /**
2
+ * DataStreamRouter — Typed Message Dispatch
3
+ *
4
+ * Replaces the 413-line if/else chain in the old AppSession.handleMessage()
5
+ * with a clean registry pattern. Each manager registers handlers for the
6
+ * message types it cares about. The router dispatches incoming messages
7
+ * to all matching handlers.
8
+ *
9
+ * Two levels of dispatch:
10
+ *
11
+ * 1. **MessageHandlerRegistry** — routes by top-level `message.type`
12
+ * (e.g., "tpa_connection_ack", "settings_update", "data_stream",
13
+ * "device_state_update", "capabilities_update", etc.)
14
+ *
15
+ * 2. **DataStreamRouter** — routes DATA_STREAM messages by `streamType`
16
+ * (e.g., "transcription:en", "translation:en-ja", "button_press",
17
+ * "phone_notification", etc.)
18
+ *
19
+ * MentraSession wires them together:
20
+ * - Creates MessageHandlerRegistry
21
+ * - Creates DataStreamRouter
22
+ * - Registers DataStreamRouter.handle as the handler for "data_stream"
23
+ * - Each manager registers its handlers on one or both registries
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * const messages = new MessageHandlerRegistry();
28
+ * const streams = new DataStreamRouter();
29
+ *
30
+ * // MentraSession registers the bridge
31
+ * messages.register("data_stream", (msg) => streams.handle(msg));
32
+ *
33
+ * // TranscriptionManager registers for transcription streams
34
+ * streams.on("transcription", (streamType, data) => { ... });
35
+ *
36
+ * // DeviceManager registers for direct messages
37
+ * messages.register("device_state_update", (msg) => { ... });
38
+ * messages.register("capabilities_update", (msg) => { ... });
39
+ *
40
+ * // Dispatch an incoming message — ~5 lines instead of 413
41
+ * const msg = JSON.parse(raw);
42
+ * if (msg?.type) messages.dispatch(msg);
43
+ * ```
44
+ */
45
+ /**
46
+ * Handler for a top-level message type.
47
+ * Receives the full parsed message object.
48
+ */
49
+ export type MessageHandler = (message: any) => void;
50
+ /**
51
+ * Routes incoming messages by their `type` field to registered handlers.
52
+ * Multiple handlers can be registered for the same message type — all fire.
53
+ *
54
+ * This replaces the massive if/else chain with O(1) lookup + iteration.
55
+ */
56
+ export declare class MessageHandlerRegistry {
57
+ /**
58
+ * Map from message type string → array of handlers.
59
+ * Using an array per type supports multiple managers registering
60
+ * for the same message type (e.g., multiple subsystems interested
61
+ * in CONNECTION_ACK).
62
+ */
63
+ private handlers;
64
+ /**
65
+ * Register a handler for a specific message type.
66
+ * Multiple handlers per type are supported — all will fire.
67
+ * Returns a cleanup function that removes this specific handler.
68
+ *
69
+ * @param type - The message `type` field value to match
70
+ * @param handler - Function called with the full message object
71
+ * @returns Cleanup function to unregister this handler
72
+ */
73
+ register(type: string, handler: MessageHandler): () => void;
74
+ /**
75
+ * Dispatch a message to all handlers registered for its `type`.
76
+ * Returns true if at least one handler was called, false otherwise.
77
+ *
78
+ * Handlers are called synchronously in registration order.
79
+ * Errors in one handler do not prevent other handlers from running.
80
+ */
81
+ dispatch(message: {
82
+ type: string;
83
+ [key: string]: any;
84
+ }): boolean;
85
+ /**
86
+ * Check whether any handlers are registered for a message type.
87
+ */
88
+ has(type: string): boolean;
89
+ /**
90
+ * Remove all handlers for all message types.
91
+ * Called during session cleanup/disconnect.
92
+ */
93
+ clear(): void;
94
+ }
95
+ /**
96
+ * Handler for a DATA_STREAM sub-message.
97
+ *
98
+ * @param streamType - The full stream type string (e.g., "transcription:en", "button_press")
99
+ * @param data - The payload data from the DATA_STREAM message (already unwrapped)
100
+ * @param message - The full raw DATA_STREAM message (for handlers that need metadata)
101
+ */
102
+ export type StreamHandler = (streamType: string, data: any, message: any) => void;
103
+ /**
104
+ * Routes DATA_STREAM messages to handlers based on `streamType`.
105
+ *
106
+ * Supports two matching strategies:
107
+ *
108
+ * 1. **Exact match** — `streamType === registeredKey`
109
+ * e.g., registered "button_press" matches incoming "button_press"
110
+ *
111
+ * 2. **Prefix match** — `streamType.startsWith(registeredPrefix)`
112
+ * e.g., registered "transcription" matches "transcription:en", "transcription:auto"
113
+ * e.g., registered "translation" matches "translation:en-ja", "translation:auto-es"
114
+ * e.g., registered "touch_event" matches "touch_event:triple_tap"
115
+ *
116
+ * ALL matching handlers fire (not just the first match).
117
+ * This is critical for supporting multiple simultaneous forLanguage() calls:
118
+ *
119
+ * ```ts
120
+ * // Both handlers fire for "transcription:en" messages
121
+ * router.on("transcription:en", handlerA);
122
+ * router.on("transcription:en", handlerB);
123
+ *
124
+ * // Prefix handler also fires for "transcription:en" messages
125
+ * router.on("transcription", handlerC); // matches all transcription:*
126
+ * ```
127
+ *
128
+ * Matching order: exact matches first, then prefix matches (longest prefix first).
129
+ * Within the same key, handlers fire in registration order.
130
+ */
131
+ export declare class DataStreamRouter {
132
+ /**
133
+ * Map from stream key (exact or prefix) → array of handlers.
134
+ */
135
+ private handlers;
136
+ /**
137
+ * Cached sorted prefix keys for efficient matching.
138
+ * Invalidated when handlers are added or removed.
139
+ * Sorted by length descending so longest prefix matches first.
140
+ */
141
+ private prefixKeysCache;
142
+ /**
143
+ * Register a handler for a stream type or prefix.
144
+ *
145
+ * @param key - Stream type to match. Can be:
146
+ * - Exact: "button_press", "transcription:en", "phone_notification"
147
+ * - Prefix: "transcription" (matches "transcription:en", "transcription:auto", etc.)
148
+ * @param handler - Called with (streamType, data, fullMessage) for each match
149
+ * @returns Cleanup function to unregister this handler
150
+ *
151
+ * @example
152
+ * ```ts
153
+ * // Exact match — only "button_press"
154
+ * const stop = router.on("button_press", (st, data) => { ... });
155
+ *
156
+ * // Prefix match — all transcription streams
157
+ * const stop = router.on("transcription", (st, data) => { ... });
158
+ *
159
+ * // Specific language
160
+ * const stop = router.on("transcription:en", (st, data) => { ... });
161
+ *
162
+ * // Later: unsubscribe
163
+ * stop();
164
+ * ```
165
+ */
166
+ on(key: string, handler: StreamHandler): () => void;
167
+ /**
168
+ * Dispatch a DATA_STREAM message to all matching handlers.
169
+ *
170
+ * Expects a message shaped like:
171
+ * ```json
172
+ * {
173
+ * "type": "data_stream",
174
+ * "streamType": "transcription:en",
175
+ * "data": { "text": "hello", "isFinal": true, ... }
176
+ * }
177
+ * ```
178
+ *
179
+ * Returns true if at least one handler was called.
180
+ */
181
+ handle(message: any): boolean;
182
+ /**
183
+ * Check whether any handlers are registered for a stream key.
184
+ */
185
+ has(key: string): boolean;
186
+ /**
187
+ * Get all registered stream keys (both exact and prefix).
188
+ * Useful for deriving the current subscription set.
189
+ */
190
+ getRegisteredKeys(): string[];
191
+ /**
192
+ * Remove all handlers.
193
+ * Called during session cleanup/disconnect.
194
+ */
195
+ clear(): void;
196
+ /**
197
+ * Get sorted prefix keys for matching, with longest first.
198
+ * Uses a cache that's invalidated when handlers change.
199
+ */
200
+ private getPrefixKeys;
201
+ }
202
+ /**
203
+ * Derive the set of subscription strings from the DataStreamRouter's
204
+ * registered handler keys. This is used by MentraSession to compute
205
+ * the SUBSCRIPTION_UPDATE message payload.
206
+ *
207
+ * The logic:
208
+ * - Each registered key on the DataStreamRouter represents a desired subscription.
209
+ * - Keys like "transcription" (prefix) map to "transcription:auto" subscription.
210
+ * - Keys like "transcription:en" (exact) map to "transcription:en" subscription.
211
+ * - Non-subscribable keys (e.g., internal-only) are filtered out.
212
+ *
213
+ * @param router - The DataStreamRouter to derive subscriptions from
214
+ * @param additionalSubscriptions - Extra subscriptions from other sources
215
+ * (e.g., DeviceManager state subscriptions that don't go through the router)
216
+ * @returns Deduplicated array of subscription strings
217
+ */
218
+ export declare function deriveSubscriptions(router: DataStreamRouter, additionalSubscriptions?: Set<string>): string[];
219
+ //# sourceMappingURL=DataStreamRouter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DataStreamRouter.d.ts","sourceRoot":"","sources":["../../src/session/DataStreamRouter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAIH;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,EAAE,GAAG,KAAK,IAAI,CAAC;AAEpD;;;;;GAKG;AACH,qBAAa,sBAAsB;IACjC;;;;;OAKG;IACH,OAAO,CAAC,QAAQ,CAAuC;IAEvD;;;;;;;;OAQG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,MAAM,IAAI;IAuB3D;;;;;;OAMG;IACH,QAAQ,CAAC,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,GAAG,OAAO;IAoBhE;;OAEG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAK1B;;;OAGG;IACH,KAAK,IAAI,IAAI;CAGd;AAID;;;;;;GAMG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,KAAK,IAAI,CAAC;AAElF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,qBAAa,gBAAgB;IAC3B;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAsC;IAEtD;;;;OAIG;IACH,OAAO,CAAC,eAAe,CAAyB;IAEhD;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,GAAG,MAAM,IAAI;IAyBnD;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO;IAyD7B;;OAEG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAKzB;;;OAGG;IACH,iBAAiB,IAAI,MAAM,EAAE;IAO7B;;;OAGG;IACH,KAAK,IAAI,IAAI;IAOb;;;OAGG;IACH,OAAO,CAAC,aAAa;CAMtB;AAID;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,gBAAgB,EAAE,uBAAuB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,MAAM,EAAE,CA8B7G"}