@mentra/miniapp 0.3.0-dev.0

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 (277) hide show
  1. package/README.md +259 -0
  2. package/dist/background/index.d.ts +59 -0
  3. package/dist/background/index.d.ts.map +1 -0
  4. package/dist/background/index.js +25 -0
  5. package/dist/background/index.js.map +1 -0
  6. package/dist/background/register.d.ts +38 -0
  7. package/dist/background/register.d.ts.map +1 -0
  8. package/dist/background/register.js +75 -0
  9. package/dist/background/register.js.map +1 -0
  10. package/dist/dev-reload.d.ts +21 -0
  11. package/dist/dev-reload.d.ts.map +1 -0
  12. package/dist/dev-reload.js +62 -0
  13. package/dist/dev-reload.js.map +1 -0
  14. package/dist/envelope.d.ts +23 -0
  15. package/dist/envelope.d.ts.map +1 -0
  16. package/dist/envelope.js +47 -0
  17. package/dist/envelope.js.map +1 -0
  18. package/dist/globals.d.ts +54 -0
  19. package/dist/globals.d.ts.map +1 -0
  20. package/dist/globals.js +12 -0
  21. package/dist/globals.js.map +1 -0
  22. package/dist/index.d.ts +58 -0
  23. package/dist/index.d.ts.map +1 -0
  24. package/dist/index.js +31 -0
  25. package/dist/index.js.map +1 -0
  26. package/dist/modules/actions.d.ts +54 -0
  27. package/dist/modules/actions.d.ts.map +1 -0
  28. package/dist/modules/actions.js +122 -0
  29. package/dist/modules/actions.js.map +1 -0
  30. package/dist/modules/auth.d.ts +25 -0
  31. package/dist/modules/auth.d.ts.map +1 -0
  32. package/dist/modules/auth.js +52 -0
  33. package/dist/modules/auth.js.map +1 -0
  34. package/dist/modules/base64.d.ts +16 -0
  35. package/dist/modules/base64.d.ts.map +1 -0
  36. package/dist/modules/base64.js +92 -0
  37. package/dist/modules/base64.js.map +1 -0
  38. package/dist/modules/blob.d.ts +161 -0
  39. package/dist/modules/blob.d.ts.map +1 -0
  40. package/dist/modules/blob.js +277 -0
  41. package/dist/modules/blob.js.map +1 -0
  42. package/dist/modules/camera.d.ts +137 -0
  43. package/dist/modules/camera.d.ts.map +1 -0
  44. package/dist/modules/camera.js +104 -0
  45. package/dist/modules/camera.js.map +1 -0
  46. package/dist/modules/cloud.d.ts +34 -0
  47. package/dist/modules/cloud.d.ts.map +1 -0
  48. package/dist/modules/cloud.js +70 -0
  49. package/dist/modules/cloud.js.map +1 -0
  50. package/dist/modules/dashboard.d.ts +16 -0
  51. package/dist/modules/dashboard.d.ts.map +1 -0
  52. package/dist/modules/dashboard.js +27 -0
  53. package/dist/modules/dashboard.js.map +1 -0
  54. package/dist/modules/display.d.ts +106 -0
  55. package/dist/modules/display.d.ts.map +1 -0
  56. package/dist/modules/display.js +57 -0
  57. package/dist/modules/display.js.map +1 -0
  58. package/dist/modules/events.d.ts +167 -0
  59. package/dist/modules/events.d.ts.map +1 -0
  60. package/dist/modules/events.js +123 -0
  61. package/dist/modules/events.js.map +1 -0
  62. package/dist/modules/glasses.d.ts +28 -0
  63. package/dist/modules/glasses.d.ts.map +1 -0
  64. package/dist/modules/glasses.js +39 -0
  65. package/dist/modules/glasses.js.map +1 -0
  66. package/dist/modules/heading.d.ts +16 -0
  67. package/dist/modules/heading.d.ts.map +1 -0
  68. package/dist/modules/heading.js +20 -0
  69. package/dist/modules/heading.js.map +1 -0
  70. package/dist/modules/imu.d.ts +31 -0
  71. package/dist/modules/imu.d.ts.map +1 -0
  72. package/dist/modules/imu.js +40 -0
  73. package/dist/modules/imu.js.map +1 -0
  74. package/dist/modules/input.d.ts +34 -0
  75. package/dist/modules/input.d.ts.map +1 -0
  76. package/dist/modules/input.js +50 -0
  77. package/dist/modules/input.js.map +1 -0
  78. package/dist/modules/led.d.ts +35 -0
  79. package/dist/modules/led.d.ts.map +1 -0
  80. package/dist/modules/led.js +39 -0
  81. package/dist/modules/led.js.map +1 -0
  82. package/dist/modules/location.d.ts +27 -0
  83. package/dist/modules/location.d.ts.map +1 -0
  84. package/dist/modules/location.js +35 -0
  85. package/dist/modules/location.js.map +1 -0
  86. package/dist/modules/mic.d.ts +44 -0
  87. package/dist/modules/mic.d.ts.map +1 -0
  88. package/dist/modules/mic.js +67 -0
  89. package/dist/modules/mic.js.map +1 -0
  90. package/dist/modules/miniapps.d.ts +72 -0
  91. package/dist/modules/miniapps.d.ts.map +1 -0
  92. package/dist/modules/miniapps.js +48 -0
  93. package/dist/modules/miniapps.js.map +1 -0
  94. package/dist/modules/navigation.d.ts +326 -0
  95. package/dist/modules/navigation.d.ts.map +1 -0
  96. package/dist/modules/navigation.js +386 -0
  97. package/dist/modules/navigation.js.map +1 -0
  98. package/dist/modules/permissions.d.ts +58 -0
  99. package/dist/modules/permissions.d.ts.map +1 -0
  100. package/dist/modules/permissions.js +66 -0
  101. package/dist/modules/permissions.js.map +1 -0
  102. package/dist/modules/phone.d.ts +61 -0
  103. package/dist/modules/phone.d.ts.map +1 -0
  104. package/dist/modules/phone.js +94 -0
  105. package/dist/modules/phone.js.map +1 -0
  106. package/dist/modules/pivots/engine.d.ts +169 -0
  107. package/dist/modules/pivots/engine.d.ts.map +1 -0
  108. package/dist/modules/pivots/engine.js +779 -0
  109. package/dist/modules/pivots/engine.js.map +1 -0
  110. package/dist/modules/pivots/geometry.d.ts +84 -0
  111. package/dist/modules/pivots/geometry.d.ts.map +1 -0
  112. package/dist/modules/pivots/geometry.js +371 -0
  113. package/dist/modules/pivots/geometry.js.map +1 -0
  114. package/dist/modules/pivots/instructions.d.ts +139 -0
  115. package/dist/modules/pivots/instructions.d.ts.map +1 -0
  116. package/dist/modules/pivots/instructions.js +280 -0
  117. package/dist/modules/pivots/instructions.js.map +1 -0
  118. package/dist/modules/speaker.d.ts +163 -0
  119. package/dist/modules/speaker.d.ts.map +1 -0
  120. package/dist/modules/speaker.js +250 -0
  121. package/dist/modules/speaker.js.map +1 -0
  122. package/dist/modules/storage.d.ts +50 -0
  123. package/dist/modules/storage.d.ts.map +1 -0
  124. package/dist/modules/storage.js +99 -0
  125. package/dist/modules/storage.js.map +1 -0
  126. package/dist/modules/stream.d.ts +129 -0
  127. package/dist/modules/stream.d.ts.map +1 -0
  128. package/dist/modules/stream.js +52 -0
  129. package/dist/modules/stream.js.map +1 -0
  130. package/dist/modules/system.d.ts +45 -0
  131. package/dist/modules/system.d.ts.map +1 -0
  132. package/dist/modules/system.js +42 -0
  133. package/dist/modules/system.js.map +1 -0
  134. package/dist/modules/transcription.d.ts +67 -0
  135. package/dist/modules/transcription.d.ts.map +1 -0
  136. package/dist/modules/transcription.js +106 -0
  137. package/dist/modules/transcription.js.map +1 -0
  138. package/dist/modules/translation.d.ts +59 -0
  139. package/dist/modules/translation.d.ts.map +1 -0
  140. package/dist/modules/translation.js +119 -0
  141. package/dist/modules/translation.js.map +1 -0
  142. package/dist/modules/ui.d.ts +186 -0
  143. package/dist/modules/ui.d.ts.map +1 -0
  144. package/dist/modules/ui.js +293 -0
  145. package/dist/modules/ui.js.map +1 -0
  146. package/dist/protocol.d.ts +294 -0
  147. package/dist/protocol.d.ts.map +1 -0
  148. package/dist/protocol.js +320 -0
  149. package/dist/protocol.js.map +1 -0
  150. package/dist/react/MentraProvider.d.ts +33 -0
  151. package/dist/react/MentraProvider.d.ts.map +1 -0
  152. package/dist/react/MentraProvider.js +15 -0
  153. package/dist/react/MentraProvider.js.map +1 -0
  154. package/dist/react/MiniappHeader.d.ts +44 -0
  155. package/dist/react/MiniappHeader.d.ts.map +1 -0
  156. package/dist/react/MiniappHeader.js +32 -0
  157. package/dist/react/MiniappHeader.js.map +1 -0
  158. package/dist/react/index.d.ts +13 -0
  159. package/dist/react/index.d.ts.map +1 -0
  160. package/dist/react/index.js +9 -0
  161. package/dist/react/index.js.map +1 -0
  162. package/dist/react/useCapabilities.d.ts +26 -0
  163. package/dist/react/useCapabilities.d.ts.map +1 -0
  164. package/dist/react/useCapabilities.js +27 -0
  165. package/dist/react/useCapabilities.js.map +1 -0
  166. package/dist/react/useCapsuleHeaderStyle.d.ts +27 -0
  167. package/dist/react/useCapsuleHeaderStyle.d.ts.map +1 -0
  168. package/dist/react/useCapsuleHeaderStyle.js +36 -0
  169. package/dist/react/useCapsuleHeaderStyle.js.map +1 -0
  170. package/dist/react/useColorScheme.d.ts +18 -0
  171. package/dist/react/useColorScheme.d.ts.map +1 -0
  172. package/dist/react/useColorScheme.js +24 -0
  173. package/dist/react/useColorScheme.js.map +1 -0
  174. package/dist/react/useConnected.d.ts +17 -0
  175. package/dist/react/useConnected.d.ts.map +1 -0
  176. package/dist/react/useConnected.js +39 -0
  177. package/dist/react/useConnected.js.map +1 -0
  178. package/dist/react/useRpc.d.ts +29 -0
  179. package/dist/react/useRpc.d.ts.map +1 -0
  180. package/dist/react/useRpc.js +82 -0
  181. package/dist/react/useRpc.js.map +1 -0
  182. package/dist/react/useSafeArea.d.ts +21 -0
  183. package/dist/react/useSafeArea.d.ts.map +1 -0
  184. package/dist/react/useSafeArea.js +22 -0
  185. package/dist/react/useSafeArea.js.map +1 -0
  186. package/dist/session.d.ts +310 -0
  187. package/dist/session.d.ts.map +1 -0
  188. package/dist/session.js +653 -0
  189. package/dist/session.js.map +1 -0
  190. package/dist/sub-path-types.test-d.d.ts +28 -0
  191. package/dist/sub-path-types.test-d.d.ts.map +1 -0
  192. package/dist/sub-path-types.test-d.js +37 -0
  193. package/dist/sub-path-types.test-d.js.map +1 -0
  194. package/dist/transport/auto.d.ts +35 -0
  195. package/dist/transport/auto.d.ts.map +1 -0
  196. package/dist/transport/auto.js +125 -0
  197. package/dist/transport/auto.js.map +1 -0
  198. package/dist/transport/dispatch.d.ts +43 -0
  199. package/dist/transport/dispatch.d.ts.map +1 -0
  200. package/dist/transport/dispatch.js +91 -0
  201. package/dist/transport/dispatch.js.map +1 -0
  202. package/dist/transport/local-socket.d.ts +28 -0
  203. package/dist/transport/local-socket.d.ts.map +1 -0
  204. package/dist/transport/local-socket.js +80 -0
  205. package/dist/transport/local-socket.js.map +1 -0
  206. package/dist/transport/mock.d.ts +54 -0
  207. package/dist/transport/mock.d.ts.map +1 -0
  208. package/dist/transport/mock.js +205 -0
  209. package/dist/transport/mock.js.map +1 -0
  210. package/dist/transport/postmessage.d.ts +36 -0
  211. package/dist/transport/postmessage.d.ts.map +1 -0
  212. package/dist/transport/postmessage.js +78 -0
  213. package/dist/transport/postmessage.js.map +1 -0
  214. package/dist/transport/types.d.ts +25 -0
  215. package/dist/transport/types.d.ts.map +1 -0
  216. package/dist/transport/types.js +11 -0
  217. package/dist/transport/types.js.map +1 -0
  218. package/dist/ui/index.d.ts +98 -0
  219. package/dist/ui/index.d.ts.map +1 -0
  220. package/dist/ui/index.js +32 -0
  221. package/dist/ui/index.js.map +1 -0
  222. package/package.json +75 -0
  223. package/src/background/index.ts +152 -0
  224. package/src/background/register.ts +85 -0
  225. package/src/dev-reload.ts +60 -0
  226. package/src/envelope.ts +54 -0
  227. package/src/globals.ts +62 -0
  228. package/src/index.ts +171 -0
  229. package/src/modules/actions.ts +156 -0
  230. package/src/modules/auth.ts +68 -0
  231. package/src/modules/base64.ts +87 -0
  232. package/src/modules/blob.ts +341 -0
  233. package/src/modules/camera.ts +196 -0
  234. package/src/modules/cloud.ts +94 -0
  235. package/src/modules/dashboard.ts +31 -0
  236. package/src/modules/display.ts +122 -0
  237. package/src/modules/events.ts +264 -0
  238. package/src/modules/glasses.ts +44 -0
  239. package/src/modules/heading.ts +23 -0
  240. package/src/modules/imu.ts +44 -0
  241. package/src/modules/input.ts +71 -0
  242. package/src/modules/led.ts +61 -0
  243. package/src/modules/location.ts +39 -0
  244. package/src/modules/mic.ts +74 -0
  245. package/src/modules/miniapps.ts +90 -0
  246. package/src/modules/navigation.ts +670 -0
  247. package/src/modules/permissions.ts +84 -0
  248. package/src/modules/phone.ts +120 -0
  249. package/src/modules/pivots/engine.ts +863 -0
  250. package/src/modules/pivots/geometry.ts +409 -0
  251. package/src/modules/pivots/instructions.ts +343 -0
  252. package/src/modules/speaker.ts +328 -0
  253. package/src/modules/storage.ts +109 -0
  254. package/src/modules/stream.ts +163 -0
  255. package/src/modules/system.ts +76 -0
  256. package/src/modules/transcription.ts +128 -0
  257. package/src/modules/translation.ts +149 -0
  258. package/src/modules/ui.ts +498 -0
  259. package/src/protocol.ts +371 -0
  260. package/src/react/MentraProvider.tsx +50 -0
  261. package/src/react/MiniappHeader.tsx +122 -0
  262. package/src/react/index.ts +12 -0
  263. package/src/react/useCapabilities.ts +29 -0
  264. package/src/react/useCapsuleHeaderStyle.ts +54 -0
  265. package/src/react/useColorScheme.ts +26 -0
  266. package/src/react/useConnected.ts +47 -0
  267. package/src/react/useRpc.ts +106 -0
  268. package/src/react/useSafeArea.ts +40 -0
  269. package/src/session.ts +878 -0
  270. package/src/sub-path-types.test-d.ts +49 -0
  271. package/src/transport/auto.ts +143 -0
  272. package/src/transport/dispatch.ts +106 -0
  273. package/src/transport/local-socket.ts +93 -0
  274. package/src/transport/mock.ts +248 -0
  275. package/src/transport/postmessage.ts +95 -0
  276. package/src/transport/types.ts +26 -0
  277. package/src/ui/index.ts +122 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAKH,OAAO,EAAqB,kBAAkB,EAAC,MAAM,WAAW,CAAA;AAChE,OAAO,EAAC,gBAAgB,EAAsB,mBAAmB,EAAC,MAAM,YAAY,CAAA;AACpF,OAAO,EAAkB,sBAAsB,EAAC,MAAM,kBAAkB,CAAA;AAExE,OAAO,EAAC,YAAY,EAAC,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAC,UAAU,EAAC,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAC,WAAW,EAAC,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAC,YAAY,EAAC,MAAM,qBAAqB,CAAA;AAChD,OAAO,EAAC,cAAc,EAAC,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAC,YAAY,EAAE,KAAK,aAAa,EAAC,MAAM,kBAAkB,CAAA;AACjE,OAAO,EAAC,aAAa,EAAC,MAAM,mBAAmB,CAAA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AC,GAAG,OAAO,CAAC,OAAO,CAAC;IAsC9F,EAAE,CAAC,CAAC,SAAS,MAAM,oBAAoB,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI;IAKhG,GAAG,CAAC,CAAC,SAAS,MAAM,oBAAoB,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAAG,IAAI;IAI3F;;;;;;;OAOG;IACH,kBAAkB,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,MAAM,IAAI;IAIjE,kBAAkB,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,iBAAiB,KAAK,IAAI,GAAG,MAAM,IAAI;IAIvE,oBAAoB,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,mBAAmB,GAAG,IAAI,KAAK,IAAI,GAAG,MAAM,IAAI;IAIpF,mBAAmB,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,kBAAkB,KAAK,IAAI,GAAG,MAAM,IAAI;IAQ9E,OAAO,CAAC,aAAa;IAarB,OAAO,CAAC,UAAU;IAWlB,OAAO,CAAC,cAAc;IAkKtB,OAAO,CAAC,yBAAyB;IAMjC,OAAO,CAAC,cAAc;IAkBtB,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,kBAAkB;IAwB1B,OAAO,CAAC,SAAS;IAWjB;;;;OAIG;IACH,OAAO,CAAC,gBAAgB;CAezB;AA6BD,kEAAkE;AAClE,wBAAgB,mBAAmB,IAAI,SAAS,cAAc,EAAE,CAE/D"}
@@ -0,0 +1,653 @@
1
+ /**
2
+ * @fileoverview MiniappSession — central session object for a local miniapp.
3
+ *
4
+ * Owns the transport, the request/response correlation map, the readiness queue,
5
+ * the PONG auto-reply, the visibility state, and all per-module instances.
6
+ *
7
+ * Lifecycle:
8
+ * const session = new MiniappSession()
9
+ * await session.connect() // sends CONNECT, resolves on CONNECT_ACK
10
+ * session.display.render([...])
11
+ * ...
12
+ * session.disconnect()
13
+ */
14
+ import { EventEmitter } from "eventemitter3";
15
+ import { makeRequestId, parseEnvelope, serializeEnvelope } from "./envelope";
16
+ import { getMentraOSGlobals } from "./globals";
17
+ import { MiniappErrorCode, MiniappRequestType, MiniappResponseType } from "./protocol";
18
+ import { createTransport } from "./transport/auto";
19
+ import { CameraModule } from "./modules/camera";
20
+ import { AuthModule } from "./modules/auth";
21
+ import { CloudModule } from "./modules/cloud";
22
+ import { DashboardAPI } from "./modules/dashboard";
23
+ import { DisplayManager } from "./modules/display";
24
+ import { EventManager } from "./modules/events";
25
+ import { GlassesModule } from "./modules/glasses";
26
+ import { HeadingModule } from "./modules/heading";
27
+ import { ImuModule } from "./modules/imu";
28
+ import { InputModule } from "./modules/input";
29
+ import { LedModule } from "./modules/led";
30
+ import { LocationModule } from "./modules/location";
31
+ import { MicModule } from "./modules/mic";
32
+ import { NavigationModule } from "./modules/navigation";
33
+ import { PermissionsModule } from "./modules/permissions";
34
+ import { PhoneModule } from "./modules/phone";
35
+ import { TranscriptionModule } from "./modules/transcription";
36
+ import { TranslationModule } from "./modules/translation";
37
+ import { UIModuleImpl } from "./modules/ui";
38
+ import { SimpleStorage } from "./modules/storage";
39
+ import { SpeakerModule } from "./modules/speaker";
40
+ import { StreamModule } from "./modules/stream";
41
+ import { SystemModule } from "./modules/system";
42
+ import { MiniappsModule } from "./modules/miniapps";
43
+ import { ActionsModule } from "./modules/actions";
44
+ import { BlobModule } from "./modules/blob";
45
+ const ALL_PERMISSION_TYPES = [
46
+ "location",
47
+ "microphone",
48
+ "camera",
49
+ "notifications",
50
+ "calendar",
51
+ ];
52
+ export class NotConnectedError extends Error {
53
+ constructor(message = "MiniappSession is not connected") {
54
+ super(message);
55
+ this.code = MiniappErrorCode.NOT_CONNECTED;
56
+ this.name = "NotConnectedError";
57
+ }
58
+ }
59
+ const DEFAULT_CONNECT_TIMEOUT_MS = 10000;
60
+ // Hard ceiling on how long a single bridge request waits for the host's
61
+ // REQUEST_RESULT. Without it, a host that never responds (a hung cloud call, a
62
+ // GPS fix that never arrives, a native handler that stalls) leaves the request
63
+ // promise pending FOREVER — which is what stalled navigation at "Starting…"
64
+ // (the controller's `starting` guard never reset because start() never settled).
65
+ // 60s is generous: it covers a slow route computation while still guaranteeing
66
+ // the promise eventually rejects so callers can roll back / surface an error.
67
+ const DEFAULT_REQUEST_TIMEOUT_MS = 60000;
68
+ export class MiniappSession {
69
+ constructor(options = {}) {
70
+ /** Phone-declared glasses capabilities. Null until CONNECT_ACK arrives. */
71
+ this.capabilities = null;
72
+ this.userId = "";
73
+ this.packageName = "";
74
+ this.visibility = "foreground";
75
+ /** Host color scheme. Seeded from window.MentraOS, updated via session events. */
76
+ this.colorScheme = "light";
77
+ /** True after CONNECT_ACK. Observe with waitForReady() or the "ready" event. */
78
+ this.ready = false;
79
+ this.emitter = new EventEmitter();
80
+ this.authState = null;
81
+ this.authWaiters = new Set();
82
+ this.authRefreshPromise = null;
83
+ /**
84
+ * Outbound queue for anything sent before CONNECT_ACK. Flushed in FIFO order
85
+ * once the phone responds with CONNECT_ACK.
86
+ */
87
+ this.outboundQueue = [];
88
+ this.pendingRequests = new Map();
89
+ this.connectPromise = null;
90
+ this.disposed = false;
91
+ /** Manifest-declared permission cache. Updated on CONNECT_ACK / PERMISSIONS_UPDATE. */
92
+ this._permissions = {
93
+ location: false,
94
+ microphone: false,
95
+ camera: false,
96
+ notifications: false,
97
+ calendar: false,
98
+ };
99
+ this.transport = createTransport(options);
100
+ this.connectTimeoutMs = options.connectTimeoutMs ?? DEFAULT_CONNECT_TIMEOUT_MS;
101
+ const injected = getMentraOSGlobals();
102
+ this.packageName = options.packageName ?? injected.packageName ?? "";
103
+ if (injected.colorScheme === "light" || injected.colorScheme === "dark") {
104
+ this.colorScheme = injected.colorScheme;
105
+ }
106
+ this.auth = new AuthModule(this);
107
+ this.events = new EventManager(this);
108
+ this.speaker = new SpeakerModule(this);
109
+ this.camera = new CameraModule(this);
110
+ this.cloud = new CloudModule(this);
111
+ this.dashboard = new DashboardAPI(this);
112
+ this.display = new DisplayManager(this);
113
+ this.glasses = new GlassesModule(this);
114
+ this.heading = new HeadingModule(this);
115
+ this.imu = new ImuModule(this);
116
+ this.input = new InputModule(this);
117
+ this.led = new LedModule(this);
118
+ this.location = new LocationModule(this);
119
+ this.mic = new MicModule(this);
120
+ this.navigation = new NavigationModule(this);
121
+ this.permissions = new PermissionsModule(this);
122
+ this.phone = new PhoneModule(this);
123
+ this.storage = new SimpleStorage(this);
124
+ this.blob = new BlobModule(this);
125
+ this.stream = new StreamModule(this);
126
+ this.system = new SystemModule(this);
127
+ this.transcription = new TranscriptionModule(this);
128
+ this.translation = new TranslationModule(this);
129
+ this.ui = new UIModuleImpl(this);
130
+ this.miniapps = new MiniappsModule(this);
131
+ this.actions = new ActionsModule(this);
132
+ }
133
+ /**
134
+ * @internal — synchronous lookup against the cached manifest-declared
135
+ * permission record from CONNECT_ACK / PERMISSIONS_UPDATE. Domain modules
136
+ * use this to expose their `hasPermission` getters without going to the
137
+ * wire. Returns false until CONNECT_ACK arrives.
138
+ *
139
+ * `manifestKey` is the manifest's UPPER_CASE permission name
140
+ * (MICROPHONE, CAMERA, LOCATION, READ_NOTIFICATIONS, etc.). Maps to v3's
141
+ * lowercase canonical keys internally.
142
+ */
143
+ _hasManifestPermission(manifestKey) {
144
+ const canonical = manifestKeyToCanonical(manifestKey);
145
+ if (!canonical)
146
+ return false;
147
+ return this._permissions[canonical] === true;
148
+ }
149
+ /**
150
+ * @internal — read the current manifest-declared permission record.
151
+ * Powers session.permissions.getAll(). Returns a fresh shallow copy so
152
+ * callers can't mutate internal state.
153
+ */
154
+ _getPermissions() {
155
+ return { ...this._permissions };
156
+ }
157
+ /** @internal — current miniapp-scoped backend auth, if the host provided one. */
158
+ _getAuth() {
159
+ return this.authState ? { ...this.authState } : null;
160
+ }
161
+ /**
162
+ * @internal — wait for a scoped miniapp token. Used by session.auth; not part
163
+ * of the public SDK surface because authors should never manage wire events.
164
+ */
165
+ _waitForAuth(minTtlMs, timeoutMs = 10000) {
166
+ const current = this.authState;
167
+ if (current && this.authHasTtl(current, minTtlMs)) {
168
+ return Promise.resolve({ ...current });
169
+ }
170
+ void this.requestAuthRefresh(minTtlMs);
171
+ return new Promise((resolve, reject) => {
172
+ const waiter = {
173
+ minTtlMs,
174
+ resolve,
175
+ reject,
176
+ timer: setTimeout(() => {
177
+ this.authWaiters.delete(waiter);
178
+ reject(new NotConnectedError("Miniapp auth token is not available"));
179
+ }, timeoutMs),
180
+ };
181
+ this.authWaiters.add(waiter);
182
+ });
183
+ }
184
+ /**
185
+ * @internal — subscribe to a raw stream type. Domain modules call this; it
186
+ * delegates to the EventManager registry. Underscore prefix signals "not
187
+ * part of the public SDK surface — use session.mic.onAudioChunk /
188
+ * session.transcription.on(...)
189
+ * etc. instead."
190
+ */
191
+ _subscribe(streamType, handler) {
192
+ return this.events.subscribe(streamType, handler);
193
+ }
194
+ // -------------------------------------------------------------------------
195
+ // Connection lifecycle
196
+ // -------------------------------------------------------------------------
197
+ /**
198
+ * Connect to LocalMiniappRuntime. Idempotent — calling multiple times
199
+ * returns the same Promise.
200
+ */
201
+ connect() {
202
+ if (this.disposed) {
203
+ return Promise.reject(new NotConnectedError("MiniappSession was disposed"));
204
+ }
205
+ if (this.connectPromise)
206
+ return this.connectPromise;
207
+ // Register the readiness listener BEFORE any awaits so that a synchronous
208
+ // CONNECT_ACK delivery in tests (or the phone) can't race the subscription.
209
+ const readyPromise = new Promise((resolve, reject) => {
210
+ const timer = setTimeout(() => {
211
+ const err = new Error("MiniappSession: CONNECT_ACK timeout");
212
+ this.failAllPending({ code: MiniappErrorCode.NOT_CONNECTED, message: err.message });
213
+ this.emitter.emit("error", err);
214
+ reject(err);
215
+ }, this.connectTimeoutMs);
216
+ this.emitter.once("ready", () => {
217
+ clearTimeout(timer);
218
+ resolve();
219
+ });
220
+ this.emitter.once("error", (err) => {
221
+ clearTimeout(timer);
222
+ reject(err);
223
+ });
224
+ });
225
+ this.connectPromise = (async () => {
226
+ this.transport.onMessage((raw) => this.handleIncoming(raw));
227
+ this.transport.onDisconnect((reason) => this.handleTransportDisconnect(reason));
228
+ await this.transport.open();
229
+ const requestId = makeRequestId();
230
+ const connectPayload = {
231
+ type: MiniappRequestType.CONNECT,
232
+ packageName: this.packageName,
233
+ };
234
+ this.transport.send(serializeEnvelope({ payload: connectPayload, requestId }));
235
+ await readyPromise;
236
+ })();
237
+ return this.connectPromise;
238
+ }
239
+ /** Resolves when `ready` becomes true, or rejects if connect failed. */
240
+ waitForReady() {
241
+ if (this.ready)
242
+ return Promise.resolve();
243
+ return this.connect();
244
+ }
245
+ isConnected() {
246
+ return this.ready && this.transport.isOpen();
247
+ }
248
+ disconnect() {
249
+ if (this.disposed)
250
+ return;
251
+ this.disposed = true;
252
+ // Give listeners one synchronous chance to flush final messages
253
+ // (e.g. display.render([])) before we tear down the transport.
254
+ try {
255
+ this.emitter.emit("beforeDisconnect", "disconnect called");
256
+ }
257
+ catch (err) {
258
+ // A throwing handler must not block teardown.
259
+ console.warn("[MiniappSession] beforeDisconnect handler threw:", err);
260
+ }
261
+ this.failAllPending({ code: MiniappErrorCode.REQUEST_ABORTED, message: "Session disconnected" });
262
+ try {
263
+ this.transport.close();
264
+ }
265
+ catch {
266
+ // ignore
267
+ }
268
+ this.ready = false;
269
+ this.emitter.emit("disconnect", "disconnect called");
270
+ }
271
+ // -------------------------------------------------------------------------
272
+ // Outbound traffic — modules call these
273
+ // -------------------------------------------------------------------------
274
+ /** Send a fire-and-forget request that does not need a response. */
275
+ sendOneShot(payload) {
276
+ const envelope = { payload };
277
+ this.enqueueOrSend(serializeEnvelope(envelope));
278
+ }
279
+ /**
280
+ * Send a request and get a Promise that resolves with the REQUEST_RESULT payload.
281
+ * Rejects with a MiniappRequestError if the phone returns an error result.
282
+ *
283
+ * `opts.timeoutMs` overrides the default request timeout. Pass `0` to disable
284
+ * it entirely for inherently long-running requests whose duration is unbounded
285
+ * (e.g. audio playback that resolves only when the clip finishes) — those still
286
+ * settle via REQUEST_RESULT or `failAllPending` on disconnect, so they can't
287
+ * leak. Most requests should keep the default ceiling.
288
+ */
289
+ sendRequest(payload, opts) {
290
+ if (this.disposed) {
291
+ return Promise.reject(new NotConnectedError());
292
+ }
293
+ const requestId = makeRequestId();
294
+ const envelope = { payload, requestId };
295
+ const timeoutMs = opts?.timeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
296
+ return new Promise((resolve, reject) => {
297
+ // Reject (and drop) the request if the host never sends a REQUEST_RESULT,
298
+ // so the promise can't hang forever. The REQUEST_RESULT / failAllPending
299
+ // paths clear this timer before settling. A non-positive timeout opts out
300
+ // (long-running requests rely on the host result / disconnect to settle).
301
+ const timer = timeoutMs > 0
302
+ ? setTimeout(() => {
303
+ const pending = this.pendingRequests.get(requestId);
304
+ if (!pending)
305
+ return;
306
+ this.pendingRequests.delete(requestId);
307
+ pending.reject({
308
+ code: MiniappErrorCode.ACTION_TIMEOUT,
309
+ message: "Request timed out waiting for a response from the host",
310
+ });
311
+ }, timeoutMs)
312
+ : undefined;
313
+ this.pendingRequests.set(requestId, {
314
+ requestId,
315
+ resolve: resolve,
316
+ reject,
317
+ timer,
318
+ });
319
+ this.enqueueOrSend(serializeEnvelope(envelope));
320
+ });
321
+ }
322
+ // -------------------------------------------------------------------------
323
+ // Event emitter — external API
324
+ // -------------------------------------------------------------------------
325
+ on(event, handler) {
326
+ this.emitter.on(event, handler);
327
+ return () => this.emitter.off(event, handler);
328
+ }
329
+ off(event, handler) {
330
+ this.emitter.off(event, handler);
331
+ }
332
+ /**
333
+ * Last-chance hook before the transport closes. Fires either when the
334
+ * phone notifies the session of an imminent disconnect (~50ms grace
335
+ * window before the socket is torn down) or when this session's
336
+ * `disconnect()` is called locally. Use it to flush final cleanup
337
+ * messages — e.g. `display.render([])` — synchronously. Async work
338
+ * started here will not complete before the socket closes.
339
+ */
340
+ onBeforeDisconnect(handler) {
341
+ return this.on("beforeDisconnect", handler);
342
+ }
343
+ onVisibilityChange(handler) {
344
+ return this.on("visibility", handler);
345
+ }
346
+ onCapabilitiesChange(handler) {
347
+ return this.on("capabilities", handler);
348
+ }
349
+ onColorSchemeChange(handler) {
350
+ return this.on("colorScheme", handler);
351
+ }
352
+ // -------------------------------------------------------------------------
353
+ // Internal — transport glue
354
+ // -------------------------------------------------------------------------
355
+ enqueueOrSend(raw) {
356
+ if (this.ready) {
357
+ try {
358
+ this.transport.send(raw);
359
+ }
360
+ catch (err) {
361
+ // If send fails post-ready, treat as transport error.
362
+ this.emitter.emit("error", err);
363
+ }
364
+ return;
365
+ }
366
+ this.outboundQueue.push(raw);
367
+ }
368
+ flushQueue() {
369
+ const queue = this.outboundQueue.splice(0);
370
+ for (const raw of queue) {
371
+ try {
372
+ this.transport.send(raw);
373
+ }
374
+ catch (err) {
375
+ this.emitter.emit("error", err);
376
+ }
377
+ }
378
+ }
379
+ handleIncoming(raw) {
380
+ const envelope = parseEnvelope(raw);
381
+ if (!envelope)
382
+ return;
383
+ const payload = envelope.payload;
384
+ const type = payload?.type;
385
+ switch (type) {
386
+ case MiniappResponseType.CONNECT_ACK: {
387
+ const ack = payload;
388
+ this.userId = ack.userId ?? "";
389
+ if (ack.packageName)
390
+ this.packageName = ack.packageName;
391
+ this.capabilities = ack.capabilities ?? null;
392
+ if (ack.visibility)
393
+ this.visibility = ack.visibility;
394
+ if (ack.colorScheme === "light" || ack.colorScheme === "dark") {
395
+ this.colorScheme = ack.colorScheme;
396
+ }
397
+ if (ack.auth) {
398
+ this.applyAuth(ack.auth);
399
+ if (!this.userId)
400
+ this.userId = ack.auth.mentraUserId;
401
+ }
402
+ // Populate the manifest-declared permission cache. Older runtimes
403
+ // that don't send `permissions` leave the all-false default in place
404
+ // — `hasPermission` getters will simply return false.
405
+ if (ack.permissions)
406
+ this.applyPermissions(ack.permissions);
407
+ this.ready = true;
408
+ this.flushQueue();
409
+ this.emitter.emit("ready");
410
+ // Don't resolve request correlation here — CONNECT_ACK has no requestId.
411
+ return;
412
+ }
413
+ case MiniappResponseType.AUTH_UPDATE: {
414
+ const next = payload.auth;
415
+ if (next) {
416
+ this.applyAuth(next);
417
+ if (!this.userId)
418
+ this.userId = next.mentraUserId;
419
+ }
420
+ return;
421
+ }
422
+ case MiniappResponseType.PERMISSIONS_UPDATE: {
423
+ const next = payload.permissions;
424
+ if (next)
425
+ this.applyPermissions(next);
426
+ return;
427
+ }
428
+ case MiniappResponseType.SPEAKER_STATE: {
429
+ const state = payload.state;
430
+ if (!state)
431
+ return;
432
+ const event = {
433
+ state,
434
+ errorCode: payload.errorCode,
435
+ errorMessage: payload.errorMessage,
436
+ durationMs: payload.durationMs,
437
+ };
438
+ this.speaker._applyState(event);
439
+ this.emitter.emit("speakerState", event);
440
+ return;
441
+ }
442
+ case MiniappRequestType.PING: {
443
+ // Phone → miniapp keepalive ping. Auto-reply with PONG.
444
+ const pong = { type: MiniappResponseType.PONG };
445
+ const env = {
446
+ payload: pong,
447
+ ...(envelope.requestId ? { requestId: envelope.requestId } : {}),
448
+ };
449
+ try {
450
+ this.transport.send(serializeEnvelope(env));
451
+ }
452
+ catch {
453
+ // Ignore; next ping will fail too and runtime will unregister.
454
+ }
455
+ return;
456
+ }
457
+ case MiniappResponseType.EVENT: {
458
+ const streamType = payload.streamType;
459
+ if (!streamType)
460
+ return;
461
+ this.events._forwardEvent(streamType, payload.data);
462
+ return;
463
+ }
464
+ case MiniappResponseType.ACTION_CALL: {
465
+ // Another miniapp invoked one of our declared actions. Route to the
466
+ // registered handler (or buffer briefly for one to register). The SDK
467
+ // replies with an ACTION_RESULT request keyed by callId.
468
+ const callId = payload.callId;
469
+ const actionId = payload.actionId;
470
+ if (!callId || !actionId)
471
+ return;
472
+ const params = payload.params ?? {};
473
+ const callerPackageName = payload.callerPackageName ?? "";
474
+ this.actions._deliver(callId, actionId, params, { callerPackageName });
475
+ return;
476
+ }
477
+ case MiniappResponseType.CAPABILITIES_UPDATE: {
478
+ const cap = payload.capabilities ?? null;
479
+ this.capabilities = cap;
480
+ this.emitter.emit("capabilities", cap);
481
+ return;
482
+ }
483
+ case MiniappResponseType.VISIBILITY_CHANGE: {
484
+ const next = payload.visibility;
485
+ if (next === "foreground" || next === "background") {
486
+ this.visibility = next;
487
+ this.emitter.emit("visibility", next);
488
+ }
489
+ return;
490
+ }
491
+ case MiniappResponseType.COLOR_SCHEME_CHANGE: {
492
+ const next = payload.colorScheme;
493
+ if (next === "light" || next === "dark") {
494
+ this.colorScheme = next;
495
+ this.emitter.emit("colorScheme", next);
496
+ }
497
+ return;
498
+ }
499
+ case MiniappResponseType.REQUEST_RESULT: {
500
+ const requestId = envelope.requestId;
501
+ if (!requestId)
502
+ return;
503
+ const pending = this.pendingRequests.get(requestId);
504
+ if (!pending)
505
+ return;
506
+ this.pendingRequests.delete(requestId);
507
+ if (pending.timer)
508
+ clearTimeout(pending.timer);
509
+ if (payload.ok === false) {
510
+ const err = payload.error ?? {
511
+ code: MiniappErrorCode.INTERNAL,
512
+ message: "Unknown error",
513
+ };
514
+ pending.reject(err);
515
+ }
516
+ else {
517
+ pending.resolve(payload.data ?? null);
518
+ }
519
+ return;
520
+ }
521
+ case MiniappResponseType.WILL_DISCONNECT: {
522
+ const reason = payload.reason ?? "phone unregistering";
523
+ try {
524
+ this.emitter.emit("beforeDisconnect", reason);
525
+ }
526
+ catch (err) {
527
+ console.warn("[MiniappSession] beforeDisconnect handler threw:", err);
528
+ }
529
+ return;
530
+ }
531
+ case MiniappResponseType.ERROR: {
532
+ const err = new Error(payload.message ?? "MiniappSession error");
533
+ this.emitter.emit("error", err);
534
+ return;
535
+ }
536
+ default:
537
+ // Unknown type — drop silently. Forward-compat.
538
+ return;
539
+ }
540
+ }
541
+ handleTransportDisconnect(reason) {
542
+ this.ready = false;
543
+ this.failAllPending({ code: MiniappErrorCode.NOT_CONNECTED, message: `Transport disconnected: ${reason}` });
544
+ this.emitter.emit("disconnect", reason);
545
+ }
546
+ failAllPending(error) {
547
+ for (const pending of this.pendingRequests.values()) {
548
+ if (pending.timer)
549
+ clearTimeout(pending.timer);
550
+ pending.reject(error);
551
+ }
552
+ this.pendingRequests.clear();
553
+ // Auth waiters live outside pendingRequests — they're resolved by an
554
+ // AUTH_UPDATE push, not a correlated REQUEST_RESULT — so a transport drop,
555
+ // dispose, or CONNECT_ACK timeout must reject them here too. Otherwise an
556
+ // in-flight session.auth.getToken()/fetch() hangs until its 10s waiter
557
+ // timeout instead of failing fast with the disconnect error.
558
+ for (const waiter of Array.from(this.authWaiters)) {
559
+ clearTimeout(waiter.timer);
560
+ this.authWaiters.delete(waiter);
561
+ waiter.reject(new NotConnectedError(error.message));
562
+ }
563
+ }
564
+ authHasTtl(auth, minTtlMs) {
565
+ return auth.expiresAt - Date.now() > minTtlMs;
566
+ }
567
+ requestAuthRefresh(minTtlMs) {
568
+ if (this.authRefreshPromise)
569
+ return this.authRefreshPromise;
570
+ if (!this.ready || !this.transport.isOpen())
571
+ return Promise.resolve(null);
572
+ this.authRefreshPromise = this.sendRequest({
573
+ type: MiniappRequestType.AUTH_REFRESH,
574
+ minTtlMs,
575
+ })
576
+ .then((result) => {
577
+ const auth = result?.auth;
578
+ if (auth)
579
+ this.applyAuth(auth);
580
+ return auth ?? null;
581
+ })
582
+ .catch((err) => {
583
+ console.warn("[MiniappSession] auth refresh failed:", err);
584
+ return null;
585
+ })
586
+ .finally(() => {
587
+ this.authRefreshPromise = null;
588
+ });
589
+ return this.authRefreshPromise;
590
+ }
591
+ applyAuth(next) {
592
+ this.authState = { ...next };
593
+ for (const waiter of Array.from(this.authWaiters)) {
594
+ if (!this.authHasTtl(next, waiter.minTtlMs))
595
+ continue;
596
+ clearTimeout(waiter.timer);
597
+ this.authWaiters.delete(waiter);
598
+ waiter.resolve({ ...next });
599
+ }
600
+ this.emitter.emit("auth", { ...next });
601
+ }
602
+ /**
603
+ * Update the cached permission record. Idempotent: emits "permissions"
604
+ * only when the record actually changed. Sanitizes incoming objects to
605
+ * the v3 PermissionType union.
606
+ */
607
+ applyPermissions(next) {
608
+ let changed = false;
609
+ const updated = { ...this._permissions };
610
+ for (const k of ALL_PERMISSION_TYPES) {
611
+ const v = next[k] === true;
612
+ if (updated[k] !== v) {
613
+ updated[k] = v;
614
+ changed = true;
615
+ }
616
+ }
617
+ if (changed) {
618
+ this._permissions = updated;
619
+ this.emitter.emit("permissions", { ...updated });
620
+ }
621
+ }
622
+ }
623
+ /**
624
+ * Map a manifest UPPER_CASE permission name to the lowercase canonical key
625
+ * used by `session.permissions`. Returns null for unknown manifest keys.
626
+ *
627
+ * BACKGROUND_LOCATION + POST_NOTIFICATIONS map onto the same canonical keys
628
+ * as their non-suffixed counterparts (location / notifications) since
629
+ * `has()` is "do I have *any* form of this permission declared".
630
+ */
631
+ function manifestKeyToCanonical(manifestKey) {
632
+ switch (manifestKey.toUpperCase()) {
633
+ case "MICROPHONE":
634
+ return "microphone";
635
+ case "CAMERA":
636
+ return "camera";
637
+ case "LOCATION":
638
+ case "BACKGROUND_LOCATION":
639
+ return "location";
640
+ case "READ_NOTIFICATIONS":
641
+ case "POST_NOTIFICATIONS":
642
+ return "notifications";
643
+ case "CALENDAR":
644
+ return "calendar";
645
+ default:
646
+ return null;
647
+ }
648
+ }
649
+ /** @internal — for the permissions module's onUpdate plumbing. */
650
+ export function _allPermissionTypes() {
651
+ return ALL_PERMISSION_TYPES;
652
+ }
653
+ //# sourceMappingURL=session.js.map