@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,36 @@
1
+ /**
2
+ * @fileoverview useCapsuleHeaderStyle — ready-to-spread React CSS props that
3
+ * vertically align a header row with the host's floating capsule menu.
4
+ *
5
+ * Use this when you want full control over header markup but want the
6
+ * alignment math done for you. If you just want a stock header, use
7
+ * <MiniappHeader> instead.
8
+ *
9
+ * Example:
10
+ * const style = useCapsuleHeaderStyle()
11
+ * <header style={style}>
12
+ * <h1>Hello</h1>
13
+ * </header>
14
+ */
15
+ import { useSafeArea } from "./useSafeArea";
16
+ export function useCapsuleHeaderStyle(options = {}) {
17
+ const { leftPadding = 20, rightGap = 16, fallbackHeight = 32, fallbackMarginTop = 16 } = options;
18
+ const { insets, capsuleMenu } = useSafeArea();
19
+ const height = capsuleMenu?.height ?? fallbackHeight;
20
+ const center = capsuleMenu
21
+ ? capsuleMenu.top + capsuleMenu.height / 2 - insets.top
22
+ : fallbackMarginTop + height / 2;
23
+ const marginTop = Math.max(0, center - height / 2);
24
+ const paddingRight = capsuleMenu ? capsuleMenu.width + rightGap : leftPadding;
25
+ return {
26
+ display: "flex",
27
+ flexShrink: 0,
28
+ alignItems: "center",
29
+ justifyContent: "space-between",
30
+ paddingLeft: leftPadding,
31
+ paddingRight,
32
+ marginTop,
33
+ height,
34
+ };
35
+ }
36
+ //# sourceMappingURL=useCapsuleHeaderStyle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCapsuleHeaderStyle.js","sourceRoot":"","sources":["../../src/react/useCapsuleHeaderStyle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAA;AAazC,MAAM,UAAU,qBAAqB,CACnC,UAAwC,EAAE;IAE1C,MAAM,EAAC,WAAW,GAAG,EAAE,EAAE,QAAQ,GAAG,EAAE,EAAE,cAAc,GAAG,EAAE,EAAE,iBAAiB,GAAG,EAAE,EAAC,GAAG,OAAO,CAAA;IAC9F,MAAM,EAAC,MAAM,EAAE,WAAW,EAAC,GAAG,WAAW,EAAE,CAAA;IAE3C,MAAM,MAAM,GAAG,WAAW,EAAE,MAAM,IAAI,cAAc,CAAA;IACpD,MAAM,MAAM,GAAG,WAAW;QACxB,CAAC,CAAC,WAAW,CAAC,GAAG,GAAG,WAAW,CAAC,MAAM,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG;QACvD,CAAC,CAAC,iBAAiB,GAAG,MAAM,GAAG,CAAC,CAAA;IAClC,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,CAAC,CAAC,CAAA;IAClD,MAAM,YAAY,GAAG,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,GAAG,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAA;IAE7E,OAAO;QACL,OAAO,EAAE,MAAM;QACf,UAAU,EAAE,CAAC;QACb,UAAU,EAAE,QAAQ;QACpB,cAAc,EAAE,eAAe;QAC/B,WAAW,EAAE,WAAW;QACxB,YAAY;QACZ,SAAS;QACT,MAAM;KACP,CAAA;AACH,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @fileoverview useColorScheme — React hook that returns the host's current
3
+ * color scheme.
4
+ *
5
+ * WebView-side hook: reads `window.MentraOS.colorScheme`, injected by the host
6
+ * before the miniapp's content loads. Like `useSafeArea`, this is read once at
7
+ * mount — the host doesn't push color-scheme changes to the WebView at runtime;
8
+ * flipping the phone's theme forces a reload.
9
+ *
10
+ * IMPORTANT: this hook must NOT construct a `MiniappSession`. `MiniappSession`
11
+ * is the *background* (JSContext) API; inside a UI WebView its transport falls
12
+ * back to PostMessage and its `CONNECT` never gets an ACK from the host's UI
13
+ * router, so `session.connect()` times out ("CONNECT_ACK timeout"). UI hooks
14
+ * read host-injected globals instead (see `useSafeArea`).
15
+ */
16
+ import { type MiniappColorScheme } from "../globals";
17
+ export declare function useColorScheme(): MiniappColorScheme;
18
+ //# sourceMappingURL=useColorScheme.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useColorScheme.d.ts","sourceRoot":"","sources":["../../src/react/useColorScheme.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,EAAqB,KAAK,kBAAkB,EAAC,MAAM,YAAY,CAAA;AAEtE,wBAAgB,cAAc,IAAI,kBAAkB,CAKnD"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @fileoverview useColorScheme — React hook that returns the host's current
3
+ * color scheme.
4
+ *
5
+ * WebView-side hook: reads `window.MentraOS.colorScheme`, injected by the host
6
+ * before the miniapp's content loads. Like `useSafeArea`, this is read once at
7
+ * mount — the host doesn't push color-scheme changes to the WebView at runtime;
8
+ * flipping the phone's theme forces a reload.
9
+ *
10
+ * IMPORTANT: this hook must NOT construct a `MiniappSession`. `MiniappSession`
11
+ * is the *background* (JSContext) API; inside a UI WebView its transport falls
12
+ * back to PostMessage and its `CONNECT` never gets an ACK from the host's UI
13
+ * router, so `session.connect()` times out ("CONNECT_ACK timeout"). UI hooks
14
+ * read host-injected globals instead (see `useSafeArea`).
15
+ */
16
+ import { useState } from "react";
17
+ import { getMentraOSGlobals } from "../globals";
18
+ export function useColorScheme() {
19
+ const [scheme] = useState(() => {
20
+ return getMentraOSGlobals().colorScheme === "dark" ? "dark" : "light";
21
+ });
22
+ return scheme;
23
+ }
24
+ //# sourceMappingURL=useColorScheme.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useColorScheme.js","sourceRoot":"","sources":["../../src/react/useColorScheme.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAC,QAAQ,EAAC,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAC,kBAAkB,EAA0B,MAAM,YAAY,CAAA;AAEtE,MAAM,UAAU,cAAc;IAC5B,MAAM,CAAC,MAAM,CAAC,GAAG,QAAQ,CAAqB,GAAG,EAAE;QACjD,OAAO,kBAAkB,EAAE,CAAC,WAAW,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAA;IACvE,CAAC,CAAC,CAAA;IACF,OAAO,MAAM,CAAA;AACf,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @fileoverview useConnected — React hook that returns true while the miniapp's
3
+ * UI WebView is bridged to its background JSContext.
4
+ *
5
+ * WebView-side hook. "Connected" here means the `window.mentra` bridge is open:
6
+ * the shim has fired `mentra.ready()` and the host has bound the WebView so
7
+ * `mentra.send/on/request` flow. Tracked via the shim's `onOpen` / `onClose`.
8
+ * `onOpen` fires its callback immediately if the bridge is already open (see
9
+ * the shim), so late mounts still observe the connected state.
10
+ *
11
+ * IMPORTANT: this hook must NOT construct a `MiniappSession`. That is the
12
+ * *background* (JSContext) API; inside a UI WebView its `CONNECT` never gets an
13
+ * ACK from the host's UI router and `session.connect()` times out
14
+ * ("CONNECT_ACK timeout").
15
+ */
16
+ export declare function useConnected(): boolean;
17
+ //# sourceMappingURL=useConnected.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useConnected.d.ts","sourceRoot":"","sources":["../../src/react/useConnected.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAcH,wBAAgB,YAAY,IAAI,OAAO,CAkBtC"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * @fileoverview useConnected — React hook that returns true while the miniapp's
3
+ * UI WebView is bridged to its background JSContext.
4
+ *
5
+ * WebView-side hook. "Connected" here means the `window.mentra` bridge is open:
6
+ * the shim has fired `mentra.ready()` and the host has bound the WebView so
7
+ * `mentra.send/on/request` flow. Tracked via the shim's `onOpen` / `onClose`.
8
+ * `onOpen` fires its callback immediately if the bridge is already open (see
9
+ * the shim), so late mounts still observe the connected state.
10
+ *
11
+ * IMPORTANT: this hook must NOT construct a `MiniappSession`. That is the
12
+ * *background* (JSContext) API; inside a UI WebView its `CONNECT` never gets an
13
+ * ACK from the host's UI router and `session.connect()` times out
14
+ * ("CONNECT_ACK timeout").
15
+ */
16
+ import { useEffect, useState } from "react";
17
+ function getBridge() {
18
+ if (typeof window === "undefined")
19
+ return null;
20
+ return window.mentra ?? null;
21
+ }
22
+ export function useConnected() {
23
+ const [connected, setConnected] = useState(false);
24
+ useEffect(() => {
25
+ const bridge = getBridge();
26
+ if (!bridge)
27
+ return;
28
+ // onOpen fires immediately when the bridge is already open, so this also
29
+ // seeds the initial value without a separate synchronous read.
30
+ const offOpen = bridge.onOpen?.(() => setConnected(true));
31
+ const offClose = bridge.onClose?.(() => setConnected(false));
32
+ return () => {
33
+ offOpen?.();
34
+ offClose?.();
35
+ };
36
+ }, []);
37
+ return connected;
38
+ }
39
+ //# sourceMappingURL=useConnected.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useConnected.js","sourceRoot":"","sources":["../../src/react/useConnected.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAC,SAAS,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAA;AAOzC,SAAS,SAAS;IAChB,IAAI,OAAO,MAAM,KAAK,WAAW;QAAE,OAAO,IAAI,CAAA;IAC9C,OAAQ,MAA6C,CAAC,MAAM,IAAI,IAAI,CAAA;AACtE,CAAC;AAED,MAAM,UAAU,YAAY;IAC1B,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAU,KAAK,CAAC,CAAA;IAE1D,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;QAC1B,IAAI,CAAC,MAAM;YAAE,OAAM;QAEnB,yEAAyE;QACzE,+DAA+D;QAC/D,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAA;QACzD,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAA;QAC5D,OAAO,GAAG,EAAE;YACV,OAAO,EAAE,EAAE,CAAA;YACX,QAAQ,EAAE,EAAE,CAAA;QACd,CAAC,CAAA;IACH,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,OAAO,SAAS,CAAA;AAClB,CAAC"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * useRpc — React hook around `mentra.request(channel, ...)`.
3
+ *
4
+ * Returns a stable callable plus an `.abort()` method. The internal
5
+ * AbortController is recreated per call and bound to component lifecycle:
6
+ *
7
+ * - Calling the returned function once: abort() the previous in-flight
8
+ * call (if any), then issue a fresh request. Useful for per-keystroke
9
+ * autocomplete — every keystroke aborts the stale request.
10
+ * - Unmount: all in-flight calls abort.
11
+ * - Caller-provided `options.signal` is merged with the internal one
12
+ * via `AbortSignal.any` when available; manual fan-out otherwise.
13
+ */
14
+ import type { RpcReq, RpcRes, RpcRequestOptions } from "../modules/ui";
15
+ export interface RpcCallable<TChannels extends object, C extends keyof TChannels & string> {
16
+ (payload: RpcReq<TChannels[C]>, options?: RpcRequestOptions): Promise<RpcRes<TChannels[C]>>;
17
+ /** Abort the current in-flight call (if any). No-op if nothing is pending. */
18
+ abort(): void;
19
+ }
20
+ /**
21
+ * Returns a stable callable for an RPC channel. The callable auto-aborts
22
+ * on unmount and exposes `.abort()` for cancel-previous patterns.
23
+ *
24
+ * const autocomplete = useRpc<Channels, "places:autocomplete">("places:autocomplete")
25
+ * const suggestions = await autocomplete({query: "..."})
26
+ * autocomplete.abort() // cancel the latest in-flight call
27
+ */
28
+ export declare function useRpc<TChannels extends object, C extends keyof TChannels & string>(channel: C): RpcCallable<TChannels, C>;
29
+ //# sourceMappingURL=useRpc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRpc.d.ts","sourceRoot":"","sources":["../../src/react/useRpc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,OAAO,KAAK,EAAC,MAAM,EAAE,MAAM,EAAE,iBAAiB,EAAC,MAAM,eAAe,CAAA;AAkCpE,MAAM,WAAW,WAAW,CAAC,SAAS,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,SAAS,GAAG,MAAM;IACvF,CAAC,OAAO,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAC3F,8EAA8E;IAC9E,KAAK,IAAI,IAAI,CAAA;CACd;AAED;;;;;;;GAOG;AACH,wBAAgB,MAAM,CACpB,SAAS,SAAS,MAAM,EACxB,CAAC,SAAS,MAAM,SAAS,GAAG,MAAM,EAClC,OAAO,EAAE,CAAC,GAAG,WAAW,CAAC,SAAS,EAAE,CAAC,CAAC,CAsCvC"}
@@ -0,0 +1,82 @@
1
+ /**
2
+ * useRpc — React hook around `mentra.request(channel, ...)`.
3
+ *
4
+ * Returns a stable callable plus an `.abort()` method. The internal
5
+ * AbortController is recreated per call and bound to component lifecycle:
6
+ *
7
+ * - Calling the returned function once: abort() the previous in-flight
8
+ * call (if any), then issue a fresh request. Useful for per-keystroke
9
+ * autocomplete — every keystroke aborts the stale request.
10
+ * - Unmount: all in-flight calls abort.
11
+ * - Caller-provided `options.signal` is merged with the internal one
12
+ * via `AbortSignal.any` when available; manual fan-out otherwise.
13
+ */
14
+ import { useCallback, useEffect, useRef } from "react";
15
+ /** Walk to the global `mentra.request` (typed). */
16
+ function getMentraRequest() {
17
+ const m = globalThis.mentra;
18
+ if (!m || typeof m.request !== "function") {
19
+ throw new Error("useRpc: window.mentra.request is not available — is this miniapp running in a UI WebView with the shim injected?");
20
+ }
21
+ return m.request;
22
+ }
23
+ /** AbortSignal.any polyfill — combine multiple signals into one. */
24
+ function mergeSignals(signals) {
25
+ const ctor = AbortSignal;
26
+ if (typeof ctor.any === "function")
27
+ return ctor.any(signals);
28
+ const ctrl = new AbortController();
29
+ const onAbort = (sig) => {
30
+ if (!ctrl.signal.aborted)
31
+ ctrl.abort(sig.reason);
32
+ };
33
+ for (const s of signals) {
34
+ if (s.aborted) {
35
+ onAbort(s);
36
+ break;
37
+ }
38
+ s.addEventListener("abort", () => onAbort(s));
39
+ }
40
+ return ctrl.signal;
41
+ }
42
+ /**
43
+ * Returns a stable callable for an RPC channel. The callable auto-aborts
44
+ * on unmount and exposes `.abort()` for cancel-previous patterns.
45
+ *
46
+ * const autocomplete = useRpc<Channels, "places:autocomplete">("places:autocomplete")
47
+ * const suggestions = await autocomplete({query: "..."})
48
+ * autocomplete.abort() // cancel the latest in-flight call
49
+ */
50
+ export function useRpc(channel) {
51
+ // Latest in-flight controller. Replaced on each call.
52
+ const currentRef = useRef(null);
53
+ // Mount controller — aborts every in-flight call on unmount.
54
+ const mountRef = useRef(null);
55
+ if (mountRef.current == null)
56
+ mountRef.current = new AbortController();
57
+ useEffect(() => {
58
+ const mount = mountRef.current;
59
+ return () => {
60
+ mount.abort();
61
+ currentRef.current?.abort();
62
+ currentRef.current = null;
63
+ };
64
+ }, []);
65
+ const callable = useCallback((payload, options) => {
66
+ // Abort any previous call for this hook.
67
+ currentRef.current?.abort();
68
+ const ctrl = new AbortController();
69
+ currentRef.current = ctrl;
70
+ const signals = [ctrl.signal, mountRef.current.signal];
71
+ if (options?.signal)
72
+ signals.push(options.signal);
73
+ const signal = mergeSignals(signals);
74
+ return getMentraRequest()(channel, payload, { signal, timeout: options?.timeout });
75
+ }, [channel]);
76
+ callable.abort = () => {
77
+ currentRef.current?.abort();
78
+ currentRef.current = null;
79
+ };
80
+ return callable;
81
+ }
82
+ //# sourceMappingURL=useRpc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRpc.js","sourceRoot":"","sources":["../../src/react/useRpc.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @fileoverview useSafeArea — React hook exposing the host's safe-area insets
3
+ * and the capsule menu rect to miniapp UIs.
4
+ *
5
+ * The host injects these via window.MentraOS before content loads. This hook
6
+ * reads them once at mount — they don't currently change at runtime (the host
7
+ * would have to force a reload to update them, e.g. on orientation change).
8
+ */
9
+ import { type MiniappCapsuleMenuRect, type MiniappSafeAreaInsets } from "../globals";
10
+ export interface UseSafeAreaResult {
11
+ /** Pixel insets around the WebView content. Apply as padding on your root element. */
12
+ insets: MiniappSafeAreaInsets;
13
+ /**
14
+ * Bounding rect of the host's floating capsule menu (top-right overlay).
15
+ * Null when the host doesn't render one (e.g. older builds). Use this to
16
+ * avoid placing clickable content underneath the menu.
17
+ */
18
+ capsuleMenu: MiniappCapsuleMenuRect | null;
19
+ }
20
+ export declare function useSafeArea(): UseSafeAreaResult;
21
+ //# sourceMappingURL=useSafeArea.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSafeArea.d.ts","sourceRoot":"","sources":["../../src/react/useSafeArea.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,EAEL,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC3B,MAAM,YAAY,CAAA;AAInB,MAAM,WAAW,iBAAiB;IAChC,sFAAsF;IACtF,MAAM,EAAE,qBAAqB,CAAA;IAC7B;;;;OAIG;IACH,WAAW,EAAE,sBAAsB,GAAG,IAAI,CAAA;CAC3C;AAED,wBAAgB,WAAW,IAAI,iBAAiB,CAS/C"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @fileoverview useSafeArea — React hook exposing the host's safe-area insets
3
+ * and the capsule menu rect to miniapp UIs.
4
+ *
5
+ * The host injects these via window.MentraOS before content loads. This hook
6
+ * reads them once at mount — they don't currently change at runtime (the host
7
+ * would have to force a reload to update them, e.g. on orientation change).
8
+ */
9
+ import { useState } from "react";
10
+ import { getMentraOSGlobals, } from "../globals";
11
+ const EMPTY_INSETS = { top: 0, bottom: 0, left: 0, right: 0 };
12
+ export function useSafeArea() {
13
+ const [result] = useState(() => {
14
+ const globals = getMentraOSGlobals();
15
+ return {
16
+ insets: globals.safeAreaInsets ?? EMPTY_INSETS,
17
+ capsuleMenu: globals.capsuleMenu ?? null,
18
+ };
19
+ });
20
+ return result;
21
+ }
22
+ //# sourceMappingURL=useSafeArea.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSafeArea.js","sourceRoot":"","sources":["../../src/react/useSafeArea.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAC,QAAQ,EAAC,MAAM,OAAO,CAAA;AAE9B,OAAO,EACL,kBAAkB,GAGnB,MAAM,YAAY,CAAA;AAEnB,MAAM,YAAY,GAA0B,EAAC,GAAG,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAC,CAAA;AAalF,MAAM,UAAU,WAAW;IACzB,MAAM,CAAC,MAAM,CAAC,GAAG,QAAQ,CAAoB,GAAG,EAAE;QAChD,MAAM,OAAO,GAAG,kBAAkB,EAAE,CAAA;QACpC,OAAO;YACL,MAAM,EAAE,OAAO,CAAC,cAAc,IAAI,YAAY;YAC9C,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI,IAAI;SACzC,CAAA;IACH,CAAC,CAAC,CAAA;IACF,OAAO,MAAM,CAAA;AACf,CAAC"}
@@ -0,0 +1,310 @@
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 { MiniappColorScheme } from "./globals";
15
+ import { MiniappErrorCode, MiniappResponseType } from "./protocol";
16
+ import { CreateTransportOptions } from "./transport/auto";
17
+ import { CameraModule } from "./modules/camera";
18
+ import { AuthModule } from "./modules/auth";
19
+ import { CloudModule } from "./modules/cloud";
20
+ import { DashboardAPI } from "./modules/dashboard";
21
+ import { DisplayManager } from "./modules/display";
22
+ import { EventManager, type UnsubscribeFn } from "./modules/events";
23
+ import { GlassesModule } from "./modules/glasses";
24
+ import { HeadingModule } from "./modules/heading";
25
+ import { ImuModule } from "./modules/imu";
26
+ import { InputModule } from "./modules/input";
27
+ import { LedModule } from "./modules/led";
28
+ import { LocationModule } from "./modules/location";
29
+ import { MicModule } from "./modules/mic";
30
+ import { NavigationModule } from "./modules/navigation";
31
+ import { PermissionsModule } from "./modules/permissions";
32
+ import { PhoneModule } from "./modules/phone";
33
+ import { TranscriptionModule } from "./modules/transcription";
34
+ import { TranslationModule } from "./modules/translation";
35
+ import { type UIModule } from "./modules/ui";
36
+ import { SimpleStorage } from "./modules/storage";
37
+ import { SpeakerModule } from "./modules/speaker";
38
+ import { StreamModule } from "./modules/stream";
39
+ import { SystemModule } from "./modules/system";
40
+ import { MiniappsModule } from "./modules/miniapps";
41
+ import { ActionsModule } from "./modules/actions";
42
+ import { BlobModule } from "./modules/blob";
43
+ /**
44
+ * Typed display capabilities for the scene API. All limit fields are optional
45
+ * in the type because older hosts don't send them — treat absence as "unknown",
46
+ * not zero. Populated on the "ready" event (null in `start()`).
47
+ */
48
+ export interface DisplayCapabilities {
49
+ /** Public drawable canvas in px — raw coordinate space for `display.render()` boxes. */
50
+ width?: number;
51
+ height?: number;
52
+ /** False ⇒ the device can't position elements; scenes degrade to text walls host-side. */
53
+ canPosition?: boolean;
54
+ /** Element budgets. Rects share the text pool on container-based devices. */
55
+ maxTextElements?: number;
56
+ maxImageElements?: number;
57
+ /** Per-image dimension cap (box-level), when the device has one. */
58
+ maxImagePx?: {
59
+ width: number;
60
+ height: number;
61
+ };
62
+ shapes?: string[];
63
+ intensityLevels?: number;
64
+ partialUpdate?: boolean;
65
+ /** Legacy capability fields (resolution, isColor, maxTextLines, …) ride along. */
66
+ [key: string]: unknown;
67
+ }
68
+ /** Minimal snapshot of the currently-connected glasses. Phone-provided. */
69
+ export interface GlassesCapabilities {
70
+ /** Display block — null/absent on displayless devices (e.g. Mentra Live). */
71
+ display?: DisplayCapabilities | null;
72
+ [key: string]: unknown;
73
+ }
74
+ export type MiniappVisibility = "foreground" | "background";
75
+ export interface MiniappSessionOptions extends CreateTransportOptions {
76
+ /** Override auto-detected packageName. Normally provided via window.MentraOS. */
77
+ packageName?: string;
78
+ /** Override the ready timeout. Default 10s. */
79
+ connectTimeoutMs?: number;
80
+ }
81
+ export interface ConnectAckPayload {
82
+ type: MiniappResponseType.CONNECT_ACK;
83
+ userId: string;
84
+ packageName: string;
85
+ capabilities: GlassesCapabilities | null;
86
+ visibility?: MiniappVisibility;
87
+ colorScheme?: MiniappColorScheme;
88
+ /**
89
+ * Manifest-declared permission record. Mirrors cloud SDK v3's PermissionRecord:
90
+ * `{location, microphone, camera, notifications, calendar}` — booleans
91
+ * indicating whether the miniapp's manifest declared each. This is
92
+ * declaration-only; OS-grant state is not modeled.
93
+ */
94
+ permissions?: PermissionRecord;
95
+ /** Miniapp-scoped backend auth. Never a Core or runtime token. */
96
+ auth?: MiniappAuthState;
97
+ }
98
+ export interface MiniappAuthState {
99
+ mentraUserId: string;
100
+ oemId?: string;
101
+ token: string;
102
+ expiresAt: number;
103
+ }
104
+ export interface AuthUpdatePayload {
105
+ type: MiniappResponseType.AUTH_UPDATE;
106
+ auth?: MiniappAuthState;
107
+ }
108
+ /**
109
+ * Manifest-declared permission record. v3-aligned: lowercase canonical keys.
110
+ * Booleans indicate whether the miniapp declared each in its manifest.json.
111
+ */
112
+ export type PermissionType = "location" | "microphone" | "camera" | "notifications" | "calendar";
113
+ export type PermissionRecord = Record<PermissionType, boolean>;
114
+ export declare class NotConnectedError extends Error {
115
+ readonly code = MiniappErrorCode.NOT_CONNECTED;
116
+ constructor(message?: string);
117
+ }
118
+ export interface MiniappRequestError {
119
+ code: string;
120
+ message: string;
121
+ }
122
+ type SessionEmitterEvents = {
123
+ ready: () => void;
124
+ error: (error: Error) => void;
125
+ /**
126
+ * Last-chance hook before the transport closes. Fires when the phone
127
+ * sends WILL_DISCONNECT, or when this session calls `disconnect()`
128
+ * locally. Handlers run synchronously and may issue one final
129
+ * `sendOneShot`/`sendRequest` (e.g. `display.render([])`); async work won't complete
130
+ * before the socket closes.
131
+ */
132
+ beforeDisconnect: (reason: string) => void;
133
+ disconnect: (reason: string) => void;
134
+ visibility: (v: MiniappVisibility) => void;
135
+ capabilities: (cap: GlassesCapabilities | null) => void;
136
+ colorScheme: (scheme: MiniappColorScheme) => void;
137
+ permissions: (perms: PermissionRecord) => void;
138
+ speakerState: (event: import("./modules/speaker").SpeakerStateEvent) => void;
139
+ auth: (auth: MiniappAuthState) => void;
140
+ };
141
+ export declare class MiniappSession {
142
+ readonly auth: AuthModule;
143
+ readonly display: DisplayManager;
144
+ /**
145
+ * Internal subscription registry + escape hatch.
146
+ *
147
+ * Domain modules (`session.mic`, `session.input`, etc.) are the canonical
148
+ * surface for typed event subscriptions. `events.subscribe(...)` remains as
149
+ * a forward-compat escape hatch for new event types not yet wrapped on a
150
+ * domain module.
151
+ */
152
+ readonly events: EventManager;
153
+ readonly speaker: SpeakerModule;
154
+ readonly camera: CameraModule;
155
+ readonly cloud: CloudModule;
156
+ readonly dashboard: DashboardAPI;
157
+ readonly glasses: GlassesModule;
158
+ readonly heading: HeadingModule;
159
+ readonly imu: ImuModule;
160
+ readonly input: InputModule;
161
+ readonly led: LedModule;
162
+ readonly location: LocationModule;
163
+ readonly mic: MicModule;
164
+ readonly navigation: NavigationModule;
165
+ readonly permissions: PermissionsModule;
166
+ readonly phone: PhoneModule;
167
+ readonly storage: SimpleStorage;
168
+ /**
169
+ * Phone-local persistent BINARY storage (`session.blob`) — the binary
170
+ * counterpart to `session.storage`. Files on disk, scoped to this miniapp.
171
+ * Writes/reads are chunked so large payloads (e.g. captured audio fed in via
172
+ * `session.mic.onAudioChunk`) never cross the bridge in one message.
173
+ */
174
+ readonly blob: BlobModule;
175
+ readonly stream: StreamModule;
176
+ readonly system: SystemModule;
177
+ readonly transcription: TranscriptionModule;
178
+ readonly translation: TranslationModule;
179
+ /**
180
+ * UI message bus to the bound WebView (when one is open).
181
+ * Background-only API surface; mirrors the WebView's `mentra` global
182
+ * with inverted buffering policy (background drops when no WebView is
183
+ * bound; the WebView buffers until ready).
184
+ */
185
+ readonly ui: UIModule;
186
+ /**
187
+ * Inter-miniapp lifecycle + discovery (list / start / stop). SYSTEM-only —
188
+ * calls reject with NOT_PERMITTED unless this miniapp is a system app.
189
+ */
190
+ readonly miniapps: MiniappsModule;
191
+ /**
192
+ * Inter-miniapp action layer. `invoke` (SYSTEM-only) calls another miniapp's
193
+ * declared action; `handle` (open to all) exposes one of your own.
194
+ */
195
+ readonly actions: ActionsModule;
196
+ /** Phone-declared glasses capabilities. Null until CONNECT_ACK arrives. */
197
+ capabilities: GlassesCapabilities | null;
198
+ userId: string;
199
+ packageName: string;
200
+ visibility: MiniappVisibility;
201
+ /** Host color scheme. Seeded from window.MentraOS, updated via session events. */
202
+ colorScheme: MiniappColorScheme;
203
+ /** True after CONNECT_ACK. Observe with waitForReady() or the "ready" event. */
204
+ ready: boolean;
205
+ private readonly transport;
206
+ private readonly connectTimeoutMs;
207
+ private readonly emitter;
208
+ private authState;
209
+ private readonly authWaiters;
210
+ private authRefreshPromise;
211
+ /**
212
+ * Outbound queue for anything sent before CONNECT_ACK. Flushed in FIFO order
213
+ * once the phone responds with CONNECT_ACK.
214
+ */
215
+ private readonly outboundQueue;
216
+ private readonly pendingRequests;
217
+ private connectPromise;
218
+ private disposed;
219
+ /** Manifest-declared permission cache. Updated on CONNECT_ACK / PERMISSIONS_UPDATE. */
220
+ private _permissions;
221
+ constructor(options?: MiniappSessionOptions);
222
+ /**
223
+ * @internal — synchronous lookup against the cached manifest-declared
224
+ * permission record from CONNECT_ACK / PERMISSIONS_UPDATE. Domain modules
225
+ * use this to expose their `hasPermission` getters without going to the
226
+ * wire. Returns false until CONNECT_ACK arrives.
227
+ *
228
+ * `manifestKey` is the manifest's UPPER_CASE permission name
229
+ * (MICROPHONE, CAMERA, LOCATION, READ_NOTIFICATIONS, etc.). Maps to v3's
230
+ * lowercase canonical keys internally.
231
+ */
232
+ _hasManifestPermission(manifestKey: string): boolean;
233
+ /**
234
+ * @internal — read the current manifest-declared permission record.
235
+ * Powers session.permissions.getAll(). Returns a fresh shallow copy so
236
+ * callers can't mutate internal state.
237
+ */
238
+ _getPermissions(): PermissionRecord;
239
+ /** @internal — current miniapp-scoped backend auth, if the host provided one. */
240
+ _getAuth(): MiniappAuthState | null;
241
+ /**
242
+ * @internal — wait for a scoped miniapp token. Used by session.auth; not part
243
+ * of the public SDK surface because authors should never manage wire events.
244
+ */
245
+ _waitForAuth(minTtlMs: number, timeoutMs?: number): Promise<MiniappAuthState>;
246
+ /**
247
+ * @internal — subscribe to a raw stream type. Domain modules call this; it
248
+ * delegates to the EventManager registry. Underscore prefix signals "not
249
+ * part of the public SDK surface — use session.mic.onAudioChunk /
250
+ * session.transcription.on(...)
251
+ * etc. instead."
252
+ */
253
+ _subscribe(streamType: string, handler: (data: unknown) => void): UnsubscribeFn;
254
+ /**
255
+ * Connect to LocalMiniappRuntime. Idempotent — calling multiple times
256
+ * returns the same Promise.
257
+ */
258
+ connect(): Promise<void>;
259
+ /** Resolves when `ready` becomes true, or rejects if connect failed. */
260
+ waitForReady(): Promise<void>;
261
+ isConnected(): boolean;
262
+ disconnect(): void;
263
+ /** Send a fire-and-forget request that does not need a response. */
264
+ sendOneShot(payload: object): void;
265
+ /**
266
+ * Send a request and get a Promise that resolves with the REQUEST_RESULT payload.
267
+ * Rejects with a MiniappRequestError if the phone returns an error result.
268
+ *
269
+ * `opts.timeoutMs` overrides the default request timeout. Pass `0` to disable
270
+ * it entirely for inherently long-running requests whose duration is unbounded
271
+ * (e.g. audio playback that resolves only when the clip finishes) — those still
272
+ * settle via REQUEST_RESULT or `failAllPending` on disconnect, so they can't
273
+ * leak. Most requests should keep the default ceiling.
274
+ */
275
+ sendRequest<TResult = unknown>(payload: object, opts?: {
276
+ timeoutMs?: number;
277
+ }): Promise<TResult>;
278
+ on<K extends keyof SessionEmitterEvents>(event: K, handler: SessionEmitterEvents[K]): () => void;
279
+ off<K extends keyof SessionEmitterEvents>(event: K, handler: SessionEmitterEvents[K]): void;
280
+ /**
281
+ * Last-chance hook before the transport closes. Fires either when the
282
+ * phone notifies the session of an imminent disconnect (~50ms grace
283
+ * window before the socket is torn down) or when this session's
284
+ * `disconnect()` is called locally. Use it to flush final cleanup
285
+ * messages — e.g. `display.render([])` — synchronously. Async work
286
+ * started here will not complete before the socket closes.
287
+ */
288
+ onBeforeDisconnect(handler: (reason: string) => void): () => void;
289
+ onVisibilityChange(handler: (v: MiniappVisibility) => void): () => void;
290
+ onCapabilitiesChange(handler: (cap: GlassesCapabilities | null) => void): () => void;
291
+ onColorSchemeChange(handler: (scheme: MiniappColorScheme) => void): () => void;
292
+ private enqueueOrSend;
293
+ private flushQueue;
294
+ private handleIncoming;
295
+ private handleTransportDisconnect;
296
+ private failAllPending;
297
+ private authHasTtl;
298
+ private requestAuthRefresh;
299
+ private applyAuth;
300
+ /**
301
+ * Update the cached permission record. Idempotent: emits "permissions"
302
+ * only when the record actually changed. Sanitizes incoming objects to
303
+ * the v3 PermissionType union.
304
+ */
305
+ private applyPermissions;
306
+ }
307
+ /** @internal — for the permissions module's onUpdate plumbing. */
308
+ export declare function _allPermissionTypes(): readonly PermissionType[];
309
+ export {};
310
+ //# sourceMappingURL=session.d.ts.map