@mentra/miniapp 0.3.0-beta.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 +60 -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 +59 -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 +170 -0
  43. package/dist/modules/camera.d.ts.map +1 -0
  44. package/dist/modules/camera.js +116 -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 +160 -0
  59. package/dist/modules/events.d.ts.map +1 -0
  60. package/dist/modules/events.js +168 -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 +95 -0
  103. package/dist/modules/phone.d.ts.map +1 -0
  104. package/dist/modules/phone.js +110 -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 +169 -0
  119. package/dist/modules/speaker.d.ts.map +1 -0
  120. package/dist/modules/speaker.js +251 -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 +75 -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 +299 -0
  147. package/dist/protocol.d.ts.map +1 -0
  148. package/dist/protocol.js +325 -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 +312 -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 +207 -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 +84 -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 +242 -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 +291 -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 +155 -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 +335 -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 +145 -0
  257. package/src/modules/translation.ts +149 -0
  258. package/src/modules/ui.ts +498 -0
  259. package/src/protocol.ts +378 -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 +886 -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 +251 -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,47 @@
1
+ /**
2
+ * @fileoverview Bridge envelope format.
3
+ *
4
+ * Every message between @mentra/miniapp and LocalMiniappRuntime is wrapped in
5
+ * this envelope for request/response correlation.
6
+ *
7
+ * { payload: {...}, requestId?: string }
8
+ */
9
+ /** Serialize an envelope for postMessage / WebSocket transport. */
10
+ export function serializeEnvelope(envelope) {
11
+ return JSON.stringify(envelope);
12
+ }
13
+ /**
14
+ * Parse a serialized envelope. Returns null for any malformed input — never throws.
15
+ * Transports should pass raw strings in and silently drop nulls.
16
+ */
17
+ export function parseEnvelope(raw) {
18
+ if (typeof raw !== "string")
19
+ return null;
20
+ let parsed;
21
+ try {
22
+ parsed = JSON.parse(raw);
23
+ }
24
+ catch {
25
+ return null;
26
+ }
27
+ if (typeof parsed !== "object" || parsed === null)
28
+ return null;
29
+ const obj = parsed;
30
+ if (typeof obj.payload !== "object" || obj.payload === null)
31
+ return null;
32
+ if (obj.requestId !== undefined && typeof obj.requestId !== "string")
33
+ return null;
34
+ return {
35
+ payload: obj.payload,
36
+ requestId: obj.requestId,
37
+ };
38
+ }
39
+ /** Generate a short random requestId. Browser-native (crypto.randomUUID). */
40
+ export function makeRequestId() {
41
+ if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
42
+ return crypto.randomUUID();
43
+ }
44
+ // Fallback for older engines: timestamp + random suffix. Not cryptographically secure.
45
+ return `req_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 10)}`;
46
+ }
47
+ //# sourceMappingURL=envelope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"envelope.js","sourceRoot":"","sources":["../src/envelope.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAQH,mEAAmE;AACnE,MAAM,UAAU,iBAAiB,CAAC,QAAyB;IACzD,OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAA;AACjC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,GAAY;IACxC,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAA;IAExC,IAAI,MAAe,CAAA;IACnB,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAC1B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAA;IACb,CAAC;IAED,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI;QAAE,OAAO,IAAI,CAAA;IAC9D,MAAM,GAAG,GAAG,MAAiC,CAAA;IAE7C,IAAI,OAAO,GAAG,CAAC,OAAO,KAAK,QAAQ,IAAI,GAAG,CAAC,OAAO,KAAK,IAAI;QAAE,OAAO,IAAI,CAAA;IACxE,IAAI,GAAG,CAAC,SAAS,KAAK,SAAS,IAAI,OAAO,GAAG,CAAC,SAAS,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAA;IAEjF,OAAO;QACL,OAAO,EAAE,GAAG,CAAC,OAAkB;QAC/B,SAAS,EAAE,GAAG,CAAC,SAA+B;KAC/C,CAAA;AACH,CAAC;AAED,6EAA6E;AAC7E,MAAM,UAAU,aAAa;IAC3B,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,MAAM,CAAC,UAAU,KAAK,UAAU,EAAE,CAAC;QAC7E,OAAO,MAAM,CAAC,UAAU,EAAE,CAAA;IAC5B,CAAC;IACD,uFAAuF;IACvF,OAAO,OAAO,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAA;AACpF,CAAC"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * @fileoverview Shape of window.MentraOS, injected by the host MentraOS app
3
+ * before the miniapp's content loads. Miniapp authors generally won't read
4
+ * this directly — use the typed React hooks (useSafeArea, etc.) instead.
5
+ */
6
+ export interface MiniappSafeAreaInsets {
7
+ top: number;
8
+ bottom: number;
9
+ left: number;
10
+ right: number;
11
+ }
12
+ export interface MiniappCapsuleMenuRect {
13
+ top: number;
14
+ right: number;
15
+ bottom: number;
16
+ left: number;
17
+ width: number;
18
+ height: number;
19
+ }
20
+ export type MiniappColorScheme = "light" | "dark";
21
+ export interface MentraOSGlobals {
22
+ /** Package id the host assigned to this miniapp (e.g. "com.mentra.example"). */
23
+ packageName?: string;
24
+ /** "ios" | "android" | other. */
25
+ platform?: string;
26
+ /** Capabilities the host exposes to this miniapp (e.g. ["share", "open_url"]). */
27
+ capabilities?: string[];
28
+ /** True when this miniapp is running locally on-device (vs. hosted in the cloud). */
29
+ miniappLocal?: boolean;
30
+ /** True when the miniapp is running via the dev workflow (QR sideload). */
31
+ miniappDeveloperMode?: boolean;
32
+ /** Safe-area insets around the WebView content. Miniapps should pad accordingly. */
33
+ safeAreaInsets?: MiniappSafeAreaInsets;
34
+ /**
35
+ * Bounding rect (in CSS pixels) of the floating capsule menu the host draws
36
+ * over the WebView. The menu lives in the top-right and miniapps should
37
+ * avoid placing interactive elements beneath it.
38
+ */
39
+ capsuleMenu?: MiniappCapsuleMenuRect;
40
+ /**
41
+ * The host's current color scheme. Miniapps can follow this to match the
42
+ * phone's appearance. Updates at runtime arrive via the session's
43
+ * `colorScheme` event — see `useColorScheme()` in @mentra/miniapp/react.
44
+ */
45
+ colorScheme?: MiniappColorScheme;
46
+ }
47
+ declare global {
48
+ interface Window {
49
+ MentraOS?: MentraOSGlobals;
50
+ }
51
+ }
52
+ /** Reads window.MentraOS safely — returns an empty object if not set. */
53
+ export declare function getMentraOSGlobals(): MentraOSGlobals;
54
+ //# sourceMappingURL=globals.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"globals.d.ts","sourceRoot":"","sources":["../src/globals.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,WAAW,qBAAqB;IACpC,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;CACd;AAED,MAAM,WAAW,sBAAsB;IACrC,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;CACf;AAED,MAAM,MAAM,kBAAkB,GAAG,OAAO,GAAG,MAAM,CAAA;AAEjD,MAAM,WAAW,eAAe;IAC9B,gFAAgF;IAChF,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,iCAAiC;IACjC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,kFAAkF;IAClF,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;IACvB,qFAAqF;IACrF,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,2EAA2E;IAC3E,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAC9B,oFAAoF;IACpF,cAAc,CAAC,EAAE,qBAAqB,CAAA;IACtC;;;;OAIG;IACH,WAAW,CAAC,EAAE,sBAAsB,CAAA;IACpC;;;;OAIG;IACH,WAAW,CAAC,EAAE,kBAAkB,CAAA;CACjC;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,QAAQ,CAAC,EAAE,eAAe,CAAA;KAC3B;CACF;AAED,yEAAyE;AACzE,wBAAgB,kBAAkB,IAAI,eAAe,CAGpD"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @fileoverview Shape of window.MentraOS, injected by the host MentraOS app
3
+ * before the miniapp's content loads. Miniapp authors generally won't read
4
+ * this directly — use the typed React hooks (useSafeArea, etc.) instead.
5
+ */
6
+ /** Reads window.MentraOS safely — returns an empty object if not set. */
7
+ export function getMentraOSGlobals() {
8
+ if (typeof window === "undefined")
9
+ return {};
10
+ return window.MentraOS ?? {};
11
+ }
12
+ //# sourceMappingURL=globals.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"globals.js","sourceRoot":"","sources":["../src/globals.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAqDH,yEAAyE;AACzE,MAAM,UAAU,kBAAkB;IAChC,IAAI,OAAO,MAAM,KAAK,WAAW;QAAE,OAAO,EAAE,CAAA;IAC5C,OAAO,MAAM,CAAC,QAAQ,IAAI,EAAE,CAAA;AAC9B,CAAC"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * @mentra/miniapp — SDK for building MentraOS local miniapps.
3
+ *
4
+ * Public entry point. Consumers do:
5
+ *
6
+ * import {MiniappSession} from "@mentra/miniapp" // background JSContext
7
+ * import {useColorScheme} from "@mentra/miniapp/react" // UI WebView hooks
8
+ * import {MiniappRequestType} from "@mentra/miniapp/protocol"
9
+ */
10
+ export { MiniappSession, NotConnectedError } from "./session";
11
+ export type { AuthUpdatePayload, ConnectAckPayload, DisplayCapabilities, GlassesCapabilities, MiniappAuthState, MiniappRequestError, MiniappSessionOptions, MiniappVisibility, } from "./session";
12
+ export type { AuthFetchOptions, AuthModule } from "./modules/auth";
13
+ export { makeRequestId, parseEnvelope, serializeEnvelope } from "./envelope";
14
+ export type { MiniappEnvelope } from "./envelope";
15
+ export { getMentraOSGlobals } from "./globals";
16
+ export type { MentraOSGlobals, MiniappCapsuleMenuRect, MiniappColorScheme, MiniappSafeAreaInsets } from "./globals";
17
+ export { MiniappErrorCode, MiniappRequestType, MiniappResponseType, MiniappStreamType } from "./protocol";
18
+ export { CLOUD_STATUS_STREAM } from "./modules/cloud";
19
+ export type { CloudClientAudioTransport, CloudClientConnectionStatus, CloudClientStatus } from "./modules/cloud";
20
+ export { HardwareType, HardwareRequirementLevel } from "@mentra/types";
21
+ export type { HardwareRequirement } from "@mentra/types";
22
+ export { createTransport } from "./transport/auto";
23
+ export type { CreateTransportOptions } from "./transport/auto";
24
+ export { PostMessageTransport } from "./transport/postmessage";
25
+ export { LocalSocketTransport } from "./transport/local-socket";
26
+ export type { LocalSocketTransportOptions } from "./transport/local-socket";
27
+ export { MockTransport, isMockExplicitlyRequested } from "./transport/mock";
28
+ export type { MockTransportOptions } from "./transport/mock";
29
+ export type { Transport, TransportDisconnectHandler, TransportMessageHandler } from "./transport/types";
30
+ export type { DisplayBreakMode, RenderBox, RenderElement, RenderOptions, RenderRectStyle, RenderResult, RenderTextStyle, ViewType, } from "./modules/display";
31
+ export type { AccelData, AudioChunkData, BatteryData, ButtonPressData, ConnectionData, HeadingData, HeadPositionData, LocationData, NotificationDismissedData, PhoneNotificationData, TouchData, TranscriptionData, TranslationData, UnsubscribeFn, VadData, WifiData, } from "./modules/events";
32
+ export type { CalendarEvent, CalendarListOptions, CalendarListResult } from "./modules/phone";
33
+ export type { PlayAudioOptions, SpeakOptions, SpeakResult, SpeakerState, SpeakerStateEvent, SpeakerStreamOptions, SpeakerStreamSampleRate, SpeakerStreamWriteResult, } from "./modules/speaker";
34
+ export { SpeakerStreamWriter, SPEAKER_STREAM_MAX_BUFFERED_MS, SPEAKER_WRITE_CHUNK_BYTES } from "./modules/speaker";
35
+ export type { CameraFovPreset, CameraFovRequest, CameraFovResult, CameraRoiPosition, PhotoTaken, SetCameraFovOptions, StartVideoRecordingOptions, StopVideoRecordingOptions, TakePhotoOptions, VideoRecordingStarted, } from "./modules/camera";
36
+ export type { DashboardMode } from "./modules/dashboard";
37
+ export type { CloudModule } from "./modules/cloud";
38
+ export type { LedColor, LedControlOptions } from "./modules/led";
39
+ export type { RestreamDestination, StartStreamOptions, StreamAudioConfig, StreamResolvedConfig, StreamResult, StreamStatus, StreamVideoConfig, } from "./modules/stream";
40
+ export type { ShareOptions, ShareResult, DownloadOptions, DownloadResult } from "./modules/system";
41
+ export type { MiniappInfo, MiniappActionInfo, MiniappCompatibility, ListMiniappsOptions } from "./modules/miniapps";
42
+ export type { ActionContext, ActionHandler, InvokeOptions } from "./modules/actions";
43
+ export type { DisplayManager } from "./modules/display";
44
+ export type { MiniappsModule } from "./modules/miniapps";
45
+ export type { ActionsModule } from "./modules/actions";
46
+ export type { GlassesModule } from "./modules/glasses";
47
+ export type { HeadingModule } from "./modules/heading";
48
+ export type { ImuModule } from "./modules/imu";
49
+ export type { InputModule } from "./modules/input";
50
+ export type { LocationModule } from "./modules/location";
51
+ export type { MicModule } from "./modules/mic";
52
+ export type { ComputedRoute, ComputedRouteStep, ComputeRouteOptions, ComputeRouteResult, LatLng, NavArrived, NavError, NavigationModule, NavManeuver, NavOffRoute, NavPermissionResult, NavPlaceDetails, NavPlaceSuggestion, NavRerouting, NavRoute, NavState, NavStep, NavUpdate, Pivot, PivotEvent, PivotOptions, RouteAvoidances, StartNavigationOptions, TravelMode, } from "./modules/navigation";
53
+ export type { PermissionsModule, PermissionErrorEvent } from "./modules/permissions";
54
+ export type { PhoneModule, PhoneNotificationsModule, PhoneCalendarModule } from "./modules/phone";
55
+ export type { TranscriptionModule, TranscriptionConfig, TranscriptionOptions } from "./modules/transcription";
56
+ export type { TranslationModule } from "./modules/translation";
57
+ export type { SpeakerModule } from "./modules/speaker";
58
+ export type { PermissionType, PermissionRecord } from "./session";
59
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AASH,OAAO,EAAC,cAAc,EAAE,iBAAiB,EAAC,MAAM,WAAW,CAAA;AAC3D,YAAY,EACV,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACnB,gBAAgB,EAChB,mBAAmB,EACnB,qBAAqB,EACrB,iBAAiB,GAClB,MAAM,WAAW,CAAA;AAClB,YAAY,EAAC,gBAAgB,EAAE,UAAU,EAAC,MAAM,gBAAgB,CAAA;AAEhE,OAAO,EAAC,aAAa,EAAE,aAAa,EAAE,iBAAiB,EAAC,MAAM,YAAY,CAAA;AAC1E,YAAY,EAAC,eAAe,EAAC,MAAM,YAAY,CAAA;AAE/C,OAAO,EAAC,kBAAkB,EAAC,MAAM,WAAW,CAAA;AAC5C,YAAY,EAAC,eAAe,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,qBAAqB,EAAC,MAAM,WAAW,CAAA;AAEjH,OAAO,EAAC,gBAAgB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,iBAAiB,EAAC,MAAM,YAAY,CAAA;AACvG,OAAO,EAAC,mBAAmB,EAAC,MAAM,iBAAiB,CAAA;AACnD,YAAY,EAAC,yBAAyB,EAAE,2BAA2B,EAAE,iBAAiB,EAAC,MAAM,iBAAiB,CAAA;AAM9G,OAAO,EAAC,YAAY,EAAE,wBAAwB,EAAC,MAAM,eAAe,CAAA;AACpE,YAAY,EAAC,mBAAmB,EAAC,MAAM,eAAe,CAAA;AAGtD,OAAO,EAAC,eAAe,EAAC,MAAM,kBAAkB,CAAA;AAChD,YAAY,EAAC,sBAAsB,EAAC,MAAM,kBAAkB,CAAA;AAC5D,OAAO,EAAC,oBAAoB,EAAC,MAAM,yBAAyB,CAAA;AAC5D,OAAO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,CAAA;AAC7B,YAAY,EAAC,iBAAiB,EAAE,oBAAoB,EAAC,MAAM,uBAAuB,CAAA;AAClF,YAAY,EAAC,WAAW,EAAE,wBAAwB,EAAE,mBAAmB,EAAC,MAAM,iBAAiB,CAAA;AAC/F,YAAY,EAAC,mBAAmB,EAAE,mBAAmB,EAAE,oBAAoB,EAAC,MAAM,yBAAyB,CAAA;AAC3G,YAAY,EAAC,iBAAiB,EAAC,MAAM,uBAAuB,CAAA;AAC5D,YAAY,EAAC,aAAa,EAAC,MAAM,mBAAmB,CAAA;AAGpD,YAAY,EAAC,cAAc,EAAE,gBAAgB,EAAC,MAAM,WAAW,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @mentra/miniapp — SDK for building MentraOS local miniapps.
3
+ *
4
+ * Public entry point. Consumers do:
5
+ *
6
+ * import {MiniappSession} from "@mentra/miniapp" // background JSContext
7
+ * import {useColorScheme} from "@mentra/miniapp/react" // UI WebView hooks
8
+ * import {MiniappRequestType} from "@mentra/miniapp/protocol"
9
+ */
10
+ import { installDevReloadListenerIfDevMode } from "./dev-reload";
11
+ // Auto-install the dev-reload listener on module import so authors get live
12
+ // reload for free in dev builds. No-op in production (gated on
13
+ // window.MentraOS.miniappDeveloperMode).
14
+ installDevReloadListenerIfDevMode();
15
+ export { MiniappSession, NotConnectedError } from "./session";
16
+ export { makeRequestId, parseEnvelope, serializeEnvelope } from "./envelope";
17
+ export { getMentraOSGlobals } from "./globals";
18
+ export { MiniappErrorCode, MiniappRequestType, MiniappResponseType, MiniappStreamType } from "./protocol";
19
+ export { CLOUD_STATUS_STREAM } from "./modules/cloud";
20
+ // Hardware requirement types — re-exported from @mentra/types so miniapp
21
+ // authors can type their miniapp.json manifest without pulling in the types
22
+ // package directly. Keep explicit exports (enums as value, interfaces as
23
+ // type) per @mentra/types' Bun-compat convention.
24
+ export { HardwareType, HardwareRequirementLevel } from "@mentra/types";
25
+ // Transports — exported for advanced uses (forced transport injection, tests)
26
+ export { createTransport } from "./transport/auto";
27
+ export { PostMessageTransport } from "./transport/postmessage";
28
+ export { LocalSocketTransport } from "./transport/local-socket";
29
+ export { MockTransport, isMockExplicitlyRequested } from "./transport/mock";
30
+ export { SpeakerStreamWriter, SPEAKER_STREAM_MAX_BUFFERED_MS, SPEAKER_WRITE_CHUNK_BYTES } from "./modules/speaker";
31
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAC,iCAAiC,EAAC,MAAM,cAAc,CAAA;AAE9D,4EAA4E;AAC5E,+DAA+D;AAC/D,yCAAyC;AACzC,iCAAiC,EAAE,CAAA;AAEnC,OAAO,EAAC,cAAc,EAAE,iBAAiB,EAAC,MAAM,WAAW,CAAA;AAa3D,OAAO,EAAC,aAAa,EAAE,aAAa,EAAE,iBAAiB,EAAC,MAAM,YAAY,CAAA;AAG1E,OAAO,EAAC,kBAAkB,EAAC,MAAM,WAAW,CAAA;AAG5C,OAAO,EAAC,gBAAgB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,iBAAiB,EAAC,MAAM,YAAY,CAAA;AACvG,OAAO,EAAC,mBAAmB,EAAC,MAAM,iBAAiB,CAAA;AAGnD,yEAAyE;AACzE,4EAA4E;AAC5E,yEAAyE;AACzE,kDAAkD;AAClD,OAAO,EAAC,YAAY,EAAE,wBAAwB,EAAC,MAAM,eAAe,CAAA;AAGpE,8EAA8E;AAC9E,OAAO,EAAC,eAAe,EAAC,MAAM,kBAAkB,CAAA;AAEhD,OAAO,EAAC,oBAAoB,EAAC,MAAM,yBAAyB,CAAA;AAC5D,OAAO,EAAC,oBAAoB,EAAC,MAAM,0BAA0B,CAAA;AAE7D,OAAO,EAAC,aAAa,EAAE,yBAAyB,EAAC,MAAM,kBAAkB,CAAA;AA4CzE,OAAO,EAAC,mBAAmB,EAAE,8BAA8B,EAAE,yBAAyB,EAAC,MAAM,mBAAmB,CAAA"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * @fileoverview ActionsModule — `session.actions`.
3
+ *
4
+ * The MCP-shaped capability layer, both directions:
5
+ * - `invoke(pkg, actionId, params)` — call another miniapp's declared action.
6
+ * SYSTEM-only; headless-wakes the target if it's stopped.
7
+ * - `handle(actionId, fn)` — expose one of your own actions. Open to all
8
+ * miniapps. Mirrors `session.ui.handle` (one handler per id, throws on
9
+ * double-register, errors propagate to the caller).
10
+ *
11
+ * `invoke` ↔ `handle` are the two ends of one wire (keyed by `actionId`), which
12
+ * is why they share this namespace rather than being split across
13
+ * `session.miniapps`.
14
+ */
15
+ import { MiniappSession } from "../session";
16
+ /** Context handed to an action handler. `callerPackageName` is host-stamped. */
17
+ export interface ActionContext {
18
+ /** The package that invoked this action (trustworthy — set by the host). */
19
+ callerPackageName: string;
20
+ }
21
+ export type ActionHandler = (params: Record<string, unknown>, ctx: ActionContext) => unknown | Promise<unknown>;
22
+ export interface InvokeOptions {
23
+ /** Overall timeout in ms (default 30s, max 120s — host-enforced). */
24
+ timeoutMs?: number;
25
+ }
26
+ export declare class ActionsModule {
27
+ private readonly session;
28
+ private readonly handlers;
29
+ /** Inbound calls buffered until their handler registers, keyed by actionId. */
30
+ private readonly buffered;
31
+ constructor(session: MiniappSession);
32
+ /**
33
+ * Invoke a declared action on another miniapp. Resolves with the handler's
34
+ * return value, rejects with a MiniappRequestError (NOT_PERMITTED,
35
+ * APP_NOT_FOUND, ACTION_NOT_FOUND, WAKE_FAILED, NO_ACTION_HANDLER,
36
+ * ACTION_TIMEOUT, PAYLOAD_TOO_LARGE, or the handler's own error). SYSTEM-only.
37
+ */
38
+ invoke<TResult = unknown>(packageName: string, actionId: string, params?: Record<string, unknown>, opts?: InvokeOptions): Promise<TResult>;
39
+ /**
40
+ * Register a handler for one of this miniapp's declared actions. One handler
41
+ * per actionId — throws synchronously on double-register. The returned
42
+ * function unregisters. Declare the action in `miniapp.json` for it to be
43
+ * invokable; an undeclared id still registers but the host never routes to it.
44
+ */
45
+ handle(actionId: string, handler: ActionHandler): () => void;
46
+ /**
47
+ * @internal — called by MiniappSession.handleIncoming on an ACTION_CALL.
48
+ * Routes to the registered handler, or buffers briefly for one to appear.
49
+ */
50
+ _deliver(callId: string, actionId: string, params: Record<string, unknown>, ctx: ActionContext): void;
51
+ private dispatch;
52
+ private sendResult;
53
+ }
54
+ //# sourceMappingURL=actions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../src/modules/actions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,EAAC,cAAc,EAAC,MAAM,YAAY,CAAA;AAEzC,gFAAgF;AAChF,MAAM,WAAW,aAAa;IAC5B,4EAA4E;IAC5E,iBAAiB,EAAE,MAAM,CAAA;CAC1B;AAED,MAAM,MAAM,aAAa,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE,aAAa,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;AAE/G,MAAM,WAAW,aAAa;IAC5B,qEAAqE;IACrE,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAiBD,qBAAa,aAAa;IAKZ,OAAO,CAAC,QAAQ,CAAC,OAAO;IAJpC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAmC;IAC5D,+EAA+E;IAC/E,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAoC;gBAEhC,OAAO,EAAE,cAAc;IAEpD;;;;;OAKG;IACH,MAAM,CAAC,OAAO,GAAG,OAAO,EACtB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,EAChB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,IAAI,CAAC,EAAE,aAAa,GACnB,OAAO,CAAC,OAAO,CAAC;IAUnB;;;;;OAKG;IACH,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,GAAG,MAAM,IAAI;IAqB5D;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE,aAAa,GAAG,IAAI;YAuBvF,QAAQ;IAmBtB,OAAO,CAAC,UAAU;CAQnB"}
@@ -0,0 +1,122 @@
1
+ /**
2
+ * @fileoverview ActionsModule — `session.actions`.
3
+ *
4
+ * The MCP-shaped capability layer, both directions:
5
+ * - `invoke(pkg, actionId, params)` — call another miniapp's declared action.
6
+ * SYSTEM-only; headless-wakes the target if it's stopped.
7
+ * - `handle(actionId, fn)` — expose one of your own actions. Open to all
8
+ * miniapps. Mirrors `session.ui.handle` (one handler per id, throws on
9
+ * double-register, errors propagate to the caller).
10
+ *
11
+ * `invoke` ↔ `handle` are the two ends of one wire (keyed by `actionId`), which
12
+ * is why they share this namespace rather than being split across
13
+ * `session.miniapps`.
14
+ */
15
+ import { MiniappErrorCode, MiniappRequestType } from "../protocol";
16
+ /**
17
+ * How long the SDK holds an inbound ACTION_CALL waiting for its handler to
18
+ * register (a just-woken miniapp registers handlers a beat after CONNECT).
19
+ * If no handler appears in this window the call is failed with
20
+ * NO_ACTION_HANDLER. Mirrors the UI bus's pre-handler buffering.
21
+ */
22
+ const HANDLER_WAIT_MS = 5000;
23
+ export class ActionsModule {
24
+ constructor(session) {
25
+ this.session = session;
26
+ this.handlers = new Map();
27
+ /** Inbound calls buffered until their handler registers, keyed by actionId. */
28
+ this.buffered = new Map();
29
+ }
30
+ /**
31
+ * Invoke a declared action on another miniapp. Resolves with the handler's
32
+ * return value, rejects with a MiniappRequestError (NOT_PERMITTED,
33
+ * APP_NOT_FOUND, ACTION_NOT_FOUND, WAKE_FAILED, NO_ACTION_HANDLER,
34
+ * ACTION_TIMEOUT, PAYLOAD_TOO_LARGE, or the handler's own error). SYSTEM-only.
35
+ */
36
+ invoke(packageName, actionId, params, opts) {
37
+ return this.session.sendRequest({
38
+ type: MiniappRequestType.ACTION_INVOKE,
39
+ targetPackageName: packageName,
40
+ actionId,
41
+ params: params ?? {},
42
+ ...(opts?.timeoutMs != null ? { timeoutMs: opts.timeoutMs } : {}),
43
+ });
44
+ }
45
+ /**
46
+ * Register a handler for one of this miniapp's declared actions. One handler
47
+ * per actionId — throws synchronously on double-register. The returned
48
+ * function unregisters. Declare the action in `miniapp.json` for it to be
49
+ * invokable; an undeclared id still registers but the host never routes to it.
50
+ */
51
+ handle(actionId, handler) {
52
+ if (this.handlers.has(actionId)) {
53
+ throw new Error(`session.actions.handle: a handler is already registered for "${actionId}"`);
54
+ }
55
+ this.handlers.set(actionId, handler);
56
+ // Flush any calls that arrived before this handler registered.
57
+ const waiting = this.buffered.get(actionId);
58
+ if (waiting) {
59
+ this.buffered.delete(actionId);
60
+ for (const call of waiting) {
61
+ clearTimeout(call.timer);
62
+ void this.dispatch(call.callId, actionId, call.params, call.ctx);
63
+ }
64
+ }
65
+ return () => {
66
+ if (this.handlers.get(actionId) === handler)
67
+ this.handlers.delete(actionId);
68
+ };
69
+ }
70
+ /**
71
+ * @internal — called by MiniappSession.handleIncoming on an ACTION_CALL.
72
+ * Routes to the registered handler, or buffers briefly for one to appear.
73
+ */
74
+ _deliver(callId, actionId, params, ctx) {
75
+ if (this.handlers.has(actionId)) {
76
+ void this.dispatch(callId, actionId, params, ctx);
77
+ return;
78
+ }
79
+ // No handler yet — buffer, and fail with NO_ACTION_HANDLER if none registers.
80
+ const timer = setTimeout(() => {
81
+ const arr = this.buffered.get(actionId);
82
+ if (arr) {
83
+ const idx = arr.findIndex((c) => c.callId === callId);
84
+ if (idx >= 0)
85
+ arr.splice(idx, 1);
86
+ if (arr.length === 0)
87
+ this.buffered.delete(actionId);
88
+ }
89
+ this.sendResult(callId, false, undefined, {
90
+ code: MiniappErrorCode.NO_ACTION_HANDLER,
91
+ message: `No handler registered for action "${actionId}"`,
92
+ });
93
+ }, HANDLER_WAIT_MS);
94
+ const arr = this.buffered.get(actionId) ?? [];
95
+ arr.push({ callId, params, ctx, timer });
96
+ this.buffered.set(actionId, arr);
97
+ }
98
+ async dispatch(callId, actionId, params, ctx) {
99
+ const handler = this.handlers.get(actionId);
100
+ if (!handler)
101
+ return;
102
+ try {
103
+ const result = await handler(params, ctx);
104
+ this.sendResult(callId, true, result ?? null);
105
+ }
106
+ catch (e) {
107
+ this.sendResult(callId, false, undefined, {
108
+ code: MiniappErrorCode.INTERNAL,
109
+ message: e?.message ?? "action handler threw",
110
+ });
111
+ }
112
+ }
113
+ sendResult(callId, ok, result, error) {
114
+ this.session.sendOneShot({
115
+ type: MiniappRequestType.ACTION_RESULT,
116
+ callId,
117
+ ok,
118
+ ...(ok ? { result } : { error }),
119
+ });
120
+ }
121
+ }
122
+ //# sourceMappingURL=actions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actions.js","sourceRoot":"","sources":["../../src/modules/actions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAC,gBAAgB,EAAE,kBAAkB,EAAC,MAAM,aAAa,CAAA;AAuBhE;;;;;GAKG;AACH,MAAM,eAAe,GAAG,IAAK,CAAA;AAE7B,MAAM,OAAO,aAAa;IAKxB,YAA6B,OAAuB;QAAvB,YAAO,GAAP,OAAO,CAAgB;QAJnC,aAAQ,GAAG,IAAI,GAAG,EAAyB,CAAA;QAC5D,+EAA+E;QAC9D,aAAQ,GAAG,IAAI,GAAG,EAA0B,CAAA;IAEN,CAAC;IAExD;;;;;OAKG;IACH,MAAM,CACJ,WAAmB,EACnB,QAAgB,EAChB,MAAgC,EAChC,IAAoB;QAEpB,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,CAAU;YACvC,IAAI,EAAE,kBAAkB,CAAC,aAAa;YACtC,iBAAiB,EAAE,WAAW;YAC9B,QAAQ;YACR,MAAM,EAAE,MA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,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;QAC3C,IAAI,CAAC,OAAO;YAAE,OAAM;QACpB,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;YACzC,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,IAAI,IAAI,CAAC,CAAA;QAC/C,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE;gBACxC,IAAI,EAAE,gBAAgB,CAAC,QAAQ;gBAC/B,OAAO,EAAG,CAAW,EAAE,OAAO,IAAI,sBAAsB;aACzD,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;IAEO,UAAU,CAAC,MAAc,EAAE,EAAW,EAAE,MAAgB,EAAE,KAAuC;QACvG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC;YACvB,IAAI,EAAE,kBAAkB,CAAC,aAAa;YACtC,MAAM;YACN,EAAE;YACF,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,EAAC,MAAM,EAAC,CAAC,CAAC,CAAC,EAAC,KAAK,EAAC,CAAC;SAC7B,CAAC,CAAA;IACJ,CAAC;CACF"}
@@ -0,0 +1,25 @@
1
+ import type { MiniappSession, MiniappAuthState } from "../session";
2
+ export interface AuthFetchOptions extends RequestInit {
3
+ /**
4
+ * Minimum remaining token lifetime before using the current token. Defaults to
5
+ * 30 seconds. If the token is absent or too close to expiry, the call waits
6
+ * for the host's next auth update.
7
+ */
8
+ minTtlMs?: number;
9
+ }
10
+ export declare class AuthModule {
11
+ private readonly session;
12
+ constructor(session: MiniappSession);
13
+ get current(): MiniappAuthState | null;
14
+ get mentraUserId(): string | null;
15
+ get oemId(): string | null;
16
+ getToken(options?: {
17
+ minTtlMs?: number;
18
+ }): Promise<string>;
19
+ getAuthHeader(options?: {
20
+ minTtlMs?: number;
21
+ }): Promise<string>;
22
+ fetch(input: RequestInfo | URL, init?: AuthFetchOptions): Promise<Response>;
23
+ onUpdate(handler: (auth: MiniappAuthState) => void): () => void;
24
+ }
25
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/modules/auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,cAAc,EAAE,gBAAgB,EAAC,MAAM,YAAY,CAAA;AAEhE,MAAM,WAAW,gBAAiB,SAAQ,WAAW;IACnD;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAID,qBAAa,UAAU;IACT,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAAP,OAAO,EAAE,cAAc;IAEpD,IAAI,OAAO,IAAI,gBAAgB,GAAG,IAAI,CAErC;IAED,IAAI,YAAY,IAAI,MAAM,GAAG,IAAI,CAEhC;IAED,IAAI,KAAK,IAAI,MAAM,GAAG,IAAI,CAEzB;IAEK,QAAQ,CAAC,OAAO,GAAE;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAK5D,aAAa,CAAC,OAAO,GAAE;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIjE,KAAK,CAAC,KAAK,EAAE,WAAW,GAAG,GAAG,EAAE,IAAI,GAAE,gBAAqB,GAAG,OAAO,CAAC,QAAQ,CAAC;IAOrF,QAAQ,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,gBAAgB,KAAK,IAAI,GAAG,MAAM,IAAI;CAGhE"}
@@ -0,0 +1,52 @@
1
+ const DEFAULT_MIN_TTL_MS = 30000;
2
+ export class AuthModule {
3
+ constructor(session) {
4
+ this.session = session;
5
+ }
6
+ get current() {
7
+ return this.session._getAuth();
8
+ }
9
+ get mentraUserId() {
10
+ return this.current?.mentraUserId ?? null;
11
+ }
12
+ get oemId() {
13
+ return this.current?.oemId ?? null;
14
+ }
15
+ async getToken(options = {}) {
16
+ const auth = await this.session._waitForAuth(options.minTtlMs ?? DEFAULT_MIN_TTL_MS);
17
+ return auth.token;
18
+ }
19
+ async getAuthHeader(options = {}) {
20
+ return `Bearer ${await this.getToken(options)}`;
21
+ }
22
+ async fetch(input, init = {}) {
23
+ const { minTtlMs, ...requestInit } = init;
24
+ const token = await this.getToken({ minTtlMs });
25
+ const headers = mergeHeaders(requestInit.headers, { Authorization: `Bearer ${token}` });
26
+ return fetch(input, { ...requestInit, headers });
27
+ }
28
+ onUpdate(handler) {
29
+ return this.session.on("auth", handler);
30
+ }
31
+ }
32
+ function mergeHeaders(base, next) {
33
+ const headers = {};
34
+ if (Array.isArray(base)) {
35
+ for (const [key, value] of base) {
36
+ headers[key] = value;
37
+ }
38
+ }
39
+ else if (typeof Headers !== "undefined" && base instanceof Headers) {
40
+ base.forEach((value, key) => {
41
+ headers[key] = value;
42
+ });
43
+ }
44
+ else if (base && typeof base === "object") {
45
+ for (const [key, value] of Object.entries(base)) {
46
+ if (typeof value === "string")
47
+ headers[key] = value;
48
+ }
49
+ }
50
+ return { ...headers, ...next };
51
+ }
52
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/modules/auth.ts"],"names":[],"mappings":"AAWA,MAAM,kBAAkB,GAAG,KAAM,CAAA;AAEjC,MAAM,OAAO,UAAU;IACrB,YAA6B,OAAuB;QAAvB,YAAO,GAAP,OAAO,CAAgB;IAAG,CAAC;IAExD,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAA;IAChC,CAAC;IAED,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,OAAO,EAAE,YAAY,IAAI,IAAI,CAAA;IAC3C,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,OAAO,EAAE,KAAK,IAAI,IAAI,CAAA;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,EAAE,CAAC;QACrE,IAAI,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;YAC1B,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;QACtB,CAAC,CAAC,CAAA;IACJ,CAAC;SAAM,IAAI,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC5C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YAChD,IAAI,OAAO,KAAK,KAAK,QAAQ;gBAAE,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;QACrD,CAAC;IACH,CAAC;IAED,OAAO,EAAC,GAAG,OAAO,EAAE,GAAG,IAAI,EAAC,CAAA;AAC9B,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @fileoverview Dependency-free base64 codec for the miniapp background runtime.
3
+ *
4
+ * The background bundle runs in a per-miniapp JS engine (JavaScriptCore on iOS,
5
+ * QuickJS on Android) where `Buffer`, `btoa`/`atob`, and Node APIs are NOT
6
+ * guaranteed to exist. `session.blob` round-trips binary as base64 strings over
7
+ * the JSON bridge, so it needs an encoder/decoder that works with nothing but
8
+ * the language. This is that — standard RFC 4648 base64, no padding tricks.
9
+ */
10
+ /** Coerce a Uint8Array / ArrayBuffer / ArrayBufferView into a Uint8Array view (no copy when possible). */
11
+ export declare function toUint8Array(input: Uint8Array | ArrayBuffer | ArrayBufferView): Uint8Array;
12
+ /** Encode bytes to a base64 string. */
13
+ export declare function bytesToBase64(input: Uint8Array | ArrayBuffer): string;
14
+ /** Decode a base64 string to bytes. Ignores whitespace; tolerant of missing padding. */
15
+ export declare function base64ToBytes(b64: string): Uint8Array;
16
+ //# sourceMappingURL=base64.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base64.d.ts","sourceRoot":"","sources":["../../src/modules/base64.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAYH,0GAA0G;AAC1G,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW,GAAG,eAAe,GAAG,UAAU,CAI1F;AAED,uCAAuC;AACvC,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW,GAAG,MAAM,CAkBrE;AAED,wFAAwF;AACxF,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAqCrD"}
@@ -0,0 +1,92 @@
1
+ /**
2
+ * @fileoverview Dependency-free base64 codec for the miniapp background runtime.
3
+ *
4
+ * The background bundle runs in a per-miniapp JS engine (JavaScriptCore on iOS,
5
+ * QuickJS on Android) where `Buffer`, `btoa`/`atob`, and Node APIs are NOT
6
+ * guaranteed to exist. `session.blob` round-trips binary as base64 strings over
7
+ * the JSON bridge, so it needs an encoder/decoder that works with nothing but
8
+ * the language. This is that — standard RFC 4648 base64, no padding tricks.
9
+ */
10
+ const ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
11
+ /** Reverse lookup table: char code → 6-bit value (or -1). Built once. */
12
+ const LOOKUP = (() => {
13
+ const t = new Int16Array(256).fill(-1);
14
+ for (let i = 0; i < ALPHABET.length; i++)
15
+ t[ALPHABET.charCodeAt(i)] = i;
16
+ t["=".charCodeAt(0)] = 0;
17
+ return t;
18
+ })();
19
+ /** Coerce a Uint8Array / ArrayBuffer / ArrayBufferView into a Uint8Array view (no copy when possible). */
20
+ export function toUint8Array(input) {
21
+ if (input instanceof Uint8Array)
22
+ return input;
23
+ if (input instanceof ArrayBuffer)
24
+ return new Uint8Array(input);
25
+ return new Uint8Array(input.buffer, input.byteOffset, input.byteLength);
26
+ }
27
+ /** Encode bytes to a base64 string. */
28
+ export function bytesToBase64(input) {
29
+ const bytes = input instanceof Uint8Array ? input : new Uint8Array(input);
30
+ const len = bytes.length;
31
+ let out = "";
32
+ let i = 0;
33
+ for (; i + 2 < len; i += 3) {
34
+ const n = (bytes[i] << 16) | (bytes[i + 1] << 8) | bytes[i + 2];
35
+ out += ALPHABET[(n >> 18) & 63] + ALPHABET[(n >> 12) & 63] + ALPHABET[(n >> 6) & 63] + ALPHABET[n & 63];
36
+ }
37
+ const rem = len - i;
38
+ if (rem === 1) {
39
+ const n = bytes[i] << 16;
40
+ out += ALPHABET[(n >> 18) & 63] + ALPHABET[(n >> 12) & 63] + "==";
41
+ }
42
+ else if (rem === 2) {
43
+ const n = (bytes[i] << 16) | (bytes[i + 1] << 8);
44
+ out += ALPHABET[(n >> 18) & 63] + ALPHABET[(n >> 12) & 63] + ALPHABET[(n >> 6) & 63] + "=";
45
+ }
46
+ return out;
47
+ }
48
+ /** Decode a base64 string to bytes. Ignores whitespace; tolerant of missing padding. */
49
+ export function base64ToBytes(b64) {
50
+ // Count valid (non-whitespace) chars and trailing '=' to size the output exactly.
51
+ let validChars = 0;
52
+ let pad = 0;
53
+ for (let i = 0; i < b64.length; i++) {
54
+ const c = b64.charCodeAt(i);
55
+ if (c === 0x3d) {
56
+ pad++;
57
+ validChars++;
58
+ }
59
+ else if (LOOKUP[c] !== -1) {
60
+ validChars++;
61
+ }
62
+ }
63
+ const fullGroups = Math.floor(validChars / 4);
64
+ const remChars = validChars - fullGroups * 4;
65
+ let outLen = fullGroups * 3 - (pad > 0 && remChars === 0 ? pad : 0);
66
+ if (remChars === 2)
67
+ outLen += 1;
68
+ else if (remChars === 3)
69
+ outLen += 2;
70
+ if (outLen < 0)
71
+ outLen = 0;
72
+ const out = new Uint8Array(outLen);
73
+ let acc = 0;
74
+ let bits = 0;
75
+ let o = 0;
76
+ for (let i = 0; i < b64.length && o < outLen; i++) {
77
+ const c = b64.charCodeAt(i);
78
+ if (c === 0x3d)
79
+ break; // '=' — end of data
80
+ const v = LOOKUP[c];
81
+ if (v === -1)
82
+ continue; // skip whitespace / stray chars
83
+ acc = (acc << 6) | v;
84
+ bits += 6;
85
+ if (bits >= 8) {
86
+ bits -= 8;
87
+ out[o++] = (acc >> bits) & 0xff;
88
+ }
89
+ }
90
+ return out;
91
+ }
92
+ //# sourceMappingURL=base64.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base64.js","sourceRoot":"","sources":["../../src/modules/base64.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,QAAQ,GAAG,kEAAkE,CAAA;AAEnF,yEAAyE;AACzE,MAAM,MAAM,GAAe,CAAC,GAAG,EAAE;IAC/B,MAAM,CAAC,GAAG,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;IACtC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE;QAAE,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;IACvE,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;IACxB,OAAO,CAAC,CAAA;AACV,CAAC,CAAC,EAAE,CAAA;AAEJ,0GAA0G;AAC1G,MAAM,UAAU,YAAY,CAAC,KAAiD;IAC5E,IAAI,KAAK,YAAY,UAAU;QAAE,OAAO,KAAK,CAAA;IAC7C,IAAI,KAAK,YAAY,WAAW;QAAE,OAAO,IAAI,UAAU,CAAC,KAAK,CAAC,CAAA;IAC9D,OAAO,IAAI,UAAU,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,CAAA;AACzE,CAAC;AAED,uCAAuC;AACvC,MAAM,UAAU,aAAa,CAAC,KAA+B;IAC3D,MAAM,KAAK,GAAG,KAAK,YAAY,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,CAAA;IACzE,MAAM,GAAG,GAAG,KAAK,CAAC,MAAM,CAAA;IACxB,IAAI,GAAG,GA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