@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,371 @@
1
+ /**
2
+ * @fileoverview Wire protocol for @mentra/miniapp.
3
+ *
4
+ * Fresh miniapp-naming enum values. No legacy tpa_/app_/applet_ prefixes.
5
+ * These values are the contract between @mentra/miniapp (running in a WebView)
6
+ * and LocalMiniappRuntime (running on the phone).
7
+ *
8
+ * IMPORTANT: This file has NO runtime dependency on @mentra/sdk. The cloud SDK's
9
+ * wire protocol enums live in @mentra/sdk/types/message-types.ts and are used
10
+ * for cloud↔app communication, not phone↔miniapp.
11
+ */
12
+
13
+ // ============================================================================
14
+ // Miniapp → phone (request, via bridge envelope)
15
+ // ============================================================================
16
+
17
+ export enum MiniappRequestType {
18
+ /** Handshake: miniapp announces itself and asks phone to bind the session. */
19
+ CONNECT = "miniapp_connect",
20
+
21
+ /** Request a fresh miniapp-scoped backend auth token. */
22
+ AUTH_REFRESH = "miniapp_auth_refresh",
23
+
24
+ /** Update the set of streams the miniapp is subscribed to. */
25
+ SUBSCRIBE = "miniapp_subscribe",
26
+
27
+ /**
28
+ * Push a legacy display layout to the glasses. The SDK no longer emits this
29
+ * (render()/RENDER replaced it); hosts keep accepting it from bundles packed
30
+ * with older SDKs and from cloud-shaped layouts.
31
+ */
32
+ DISPLAY = "miniapp_display",
33
+
34
+ /** Render a whole scene of positioned elements (replace-the-frame). */
35
+ RENDER = "miniapp_render",
36
+
37
+ /** Play an arbitrary audio URL through the phone's audio playback service. */
38
+ PLAY_AUDIO = "miniapp_play_audio",
39
+
40
+ /** Stop any audio playback this miniapp initiated. */
41
+ STOP_AUDIO = "miniapp_stop_audio",
42
+
43
+ /** Speak text via cloud TTS — phone constructs the URL. */
44
+ SPEAK = "miniapp_speak",
45
+
46
+ /**
47
+ * Live PCM output stream to the phone's audio playback service
48
+ * (speaker.createStream). OPEN provisions a native chunk player; WRITE
49
+ * appends base64 PCM (replies with {bufferedMs} for backpressure); CLOSE
50
+ * drains and finishes; ABORT drops immediately.
51
+ */
52
+ SPEAKER_STREAM_OPEN = "miniapp_speaker_stream_open",
53
+ SPEAKER_STREAM_WRITE = "miniapp_speaker_stream_write",
54
+ SPEAKER_STREAM_CLOSE = "miniapp_speaker_stream_close",
55
+ SPEAKER_STREAM_ABORT = "miniapp_speaker_stream_abort",
56
+
57
+ /** Control the glasses RGB LED. */
58
+ RGB_LED = "miniapp_rgb_led",
59
+
60
+ /** One-shot location poll. */
61
+ LOCATION_POLL = "miniapp_location_poll",
62
+
63
+ /** Start a turn-by-turn navigation trip. Android only. */
64
+ NAVIGATION_START = "miniapp_navigation_start",
65
+ /** Stop the active navigation trip (if any). */
66
+ NAVIGATION_STOP = "miniapp_navigation_stop",
67
+ /** Dev-only: nudge the simulator off-route to test rerouting. Android sim only. */
68
+ NAVIGATION_DEVIATE = "miniapp_navigation_deviate",
69
+ /** Dev-only: lock simulated locations to the wrong sidewalk for pivot-trigger testing. */
70
+ NAVIGATION_SET_WRONG_SIDEWALK = "miniapp_navigation_set_wrong_sidewalk",
71
+ /** Dev-only: take over the simulator and walk a polyline with crossings stripped. */
72
+ NAVIGATION_SET_SKIP_CROSSINGS = "miniapp_navigation_set_skip_crossings",
73
+ /** Snapshot of the active trip (or null). Lets a miniapp opening mid-trip hydrate. */
74
+ NAVIGATION_GET_STATE = "miniapp_navigation_get_state",
75
+ /** Compute a route without starting a trip. Replaces hand-rolled Directions calls. */
76
+ NAVIGATION_COMPUTE_ROUTE = "miniapp_navigation_compute_route",
77
+ /** Reverse-geocode a coordinate to a short road name + full formatted
78
+ * address. `road` backs the engine's fallback for pivots whose Routes-API
79
+ * instruction didn't include a parseable road; `address` backs UI labels for
80
+ * dropped pins / POI taps. Resolved in the v2 cloud maps service (Mapbox
81
+ * today) via the host bridge — the miniapp never holds a maps token. */
82
+ NAVIGATION_REVERSE_GEOCODE = "miniapp_navigation_reverse_geocode",
83
+ /** Type-ahead place search (autocomplete). Resolved in the v2 cloud maps
84
+ * service (Mapbox Search Box today) via the host bridge — the miniapp never
85
+ * holds a maps token. Pairs with NAVIGATION_PLACE_DETAILS via a sessionToken. */
86
+ NAVIGATION_PLACE_AUTOCOMPLETE = "miniapp_navigation_place_autocomplete",
87
+ /** Resolve an autocomplete suggestion (placeId + sessionToken) to coordinates,
88
+ * in the v2 cloud maps service via the host bridge. */
89
+ NAVIGATION_PLACE_DETAILS = "miniapp_navigation_place_details",
90
+ /** Trigger the Google Nav SDK T&C dialog up-front so start() doesn't have to. */
91
+ NAVIGATION_REQUEST_PERMISSION = "miniapp_navigation_request_permission",
92
+
93
+ /** Phone-local simple storage. */
94
+ STORAGE_GET = "miniapp_storage_get",
95
+ STORAGE_SET = "miniapp_storage_set",
96
+ STORAGE_DELETE = "miniapp_storage_delete",
97
+ STORAGE_LIST = "miniapp_storage_list",
98
+ STORAGE_CLEAR = "miniapp_storage_clear",
99
+ STORAGE_HAS = "miniapp_storage_has",
100
+ STORAGE_GET_ALL = "miniapp_storage_get_all",
101
+ STORAGE_SET_MULTIPLE = "miniapp_storage_set_multiple",
102
+ STORAGE_FLUSH = "miniapp_storage_flush",
103
+
104
+ /** Write camera FOV settings. */
105
+ CAMERA_FOV = "miniapp_camera_fov",
106
+
107
+ /** Pre-warm the glasses camera so the next takePhoto() is near-instant. */
108
+ CAMERA_WARM_UP = "miniapp_camera_warm_up",
109
+
110
+ /**
111
+ * Enable/disable raw accelerometer (IMU) streaming on the glasses. The
112
+ * accel stream also auto-enables on subscribe; this is an explicit override
113
+ * for callers who want to control the sensor directly. G2 only today.
114
+ */
115
+ IMU_SET_ENABLED = "miniapp_imu_set_enabled",
116
+
117
+ /** Share content via the OS share sheet. */
118
+ SHARE = "miniapp_share",
119
+ /** Open a URL in the system browser. */
120
+ OPEN_URL = "miniapp_open_url",
121
+ /** Copy text to the system clipboard. */
122
+ COPY_CLIPBOARD = "miniapp_copy_clipboard",
123
+ /** Download a file (triggers OS share sheet for save location). */
124
+ DOWNLOAD = "miniapp_download",
125
+
126
+ /**
127
+ * Phone-local persistent binary blob storage, scoped to (userId, packageName).
128
+ * Unlike STORAGE_* (small string KV in MMKV), blobs are arbitrary bytes written
129
+ * to the phone filesystem. Large payloads are moved in chunks (BLOB_WRITE /
130
+ * BLOB_READ) so a single bridge message never carries a multi-MB string.
131
+ */
132
+ BLOB_CREATE = "miniapp_blob_create",
133
+ BLOB_WRITE = "miniapp_blob_write",
134
+ BLOB_COMMIT = "miniapp_blob_commit",
135
+ BLOB_ABORT = "miniapp_blob_abort",
136
+ BLOB_GET = "miniapp_blob_get",
137
+ BLOB_LIST = "miniapp_blob_list",
138
+ BLOB_DELETE = "miniapp_blob_delete",
139
+ BLOB_CLEAR = "miniapp_blob_clear",
140
+ BLOB_USAGE = "miniapp_blob_usage",
141
+ BLOB_OPEN_READ = "miniapp_blob_open_read",
142
+ BLOB_READ = "miniapp_blob_read",
143
+ BLOB_CLOSE_READ = "miniapp_blob_close_read",
144
+ /** Download a URL straight into a blob, host-side (no bytes cross the bridge). */
145
+ BLOB_SET_FROM_URL = "miniapp_blob_set_from_url",
146
+ /** Open the OS file picker and import the chosen file into a blob, host-side. */
147
+ BLOB_IMPORT = "miniapp_blob_import",
148
+ /** Share a stored blob from disk via the OS share sheet (no bytes cross the bridge). */
149
+ BLOB_SHARE = "miniapp_blob_share",
150
+
151
+ /** Phone → miniapp liveness probe. Miniapp SDK auto-replies with PONG. */
152
+ PING = "miniapp_ping",
153
+
154
+ /**
155
+ * Apply transcription configuration (language hints, vocabulary, diarization).
156
+ * Phone forwards to the cloud STT layer. Fire-and-forget; cached client-side
157
+ * so future reconnect logic can re-send.
158
+ */
159
+ TRANSCRIPTION_CONFIG = "miniapp_transcription_config",
160
+
161
+ // ----- Deferred in v1 -----
162
+
163
+ /** Dashboard content update. Noop in v1. */
164
+ DASHBOARD_CONTENT_UPDATE = "miniapp_dashboard_content_update",
165
+
166
+ // ----- Photos, streaming -----
167
+ PHOTO = "miniapp_photo",
168
+ VIDEO_RECORDING_START = "miniapp_video_recording_start",
169
+ VIDEO_RECORDING_STOP = "miniapp_video_recording_stop",
170
+ STREAM_START = "miniapp_stream_start",
171
+ STREAM_STOP = "miniapp_stream_stop",
172
+ MANAGED_STREAM_START = "miniapp_managed_stream_start",
173
+ MANAGED_STREAM_STOP = "miniapp_managed_stream_stop",
174
+
175
+ /** Ask the host to open the glasses Wi-Fi setup flow (mirrors the cloud SDK's requestWifiSetup). */
176
+ REQUEST_WIFI_SETUP = "miniapp_request_wifi_setup",
177
+
178
+ // ----- Inter-miniapp interop (SYSTEM apps only) -----
179
+ /** List installed miniapps (compatibility-filtered, with declared actions). */
180
+ MINIAPPS_LIST = "miniapp_apps_list",
181
+ /** Start another miniapp (user-tap semantics). */
182
+ MINIAPPS_START = "miniapp_apps_start",
183
+ /** Stop another miniapp. */
184
+ MINIAPPS_STOP = "miniapp_apps_stop",
185
+ /** Invoke a declared action on another miniapp; headless-wakes it if stopped. */
186
+ ACTION_INVOKE = "miniapp_action_invoke",
187
+ /** Target → host: the result of a delivered ACTION_CALL, correlated by callId. */
188
+ ACTION_RESULT = "miniapp_action_result",
189
+ }
190
+
191
+ // ============================================================================
192
+ // Phone → miniapp (response or push)
193
+ // ============================================================================
194
+
195
+ export enum MiniappResponseType {
196
+ /** Response to CONNECT carrying userId, packageName, capabilities. */
197
+ CONNECT_ACK = "miniapp_connect_ack",
198
+
199
+ /** Push: a streamed event for a subscribed stream. */
200
+ EVENT = "miniapp_event",
201
+
202
+ /** Response to any request that needs a result (matched by requestId). */
203
+ REQUEST_RESULT = "miniapp_request_result",
204
+
205
+ /** Push: glasses capabilities changed. */
206
+ CAPABILITIES_UPDATE = "miniapp_capabilities_update",
207
+
208
+ /** Push: miniapp's foreground/background state changed. */
209
+ VISIBILITY_CHANGE = "miniapp_visibility_change",
210
+
211
+ /** Push: host color scheme (light/dark) changed. */
212
+ COLOR_SCHEME_CHANGE = "miniapp_color_scheme_change",
213
+
214
+ /**
215
+ * Push: speaker playback state transitioned. Per-miniapp; the runtime sends
216
+ * to the owning miniapp only. Carries {state, errorCode?, errorMessage?,
217
+ * durationMs?}. See SpeakerModule.onStateChange().
218
+ */
219
+ SPEAKER_STATE = "miniapp_speaker_state",
220
+
221
+ /**
222
+ * Push: manifest-declared permissions changed (e.g. dev miniapp re-scanned
223
+ * with updated manifest). Carries a full PermissionRecord. SDK caches it
224
+ * and fires session.permissions.onUpdate handlers.
225
+ */
226
+ PERMISSIONS_UPDATE = "miniapp_permissions_update",
227
+
228
+ /**
229
+ * Push: miniapp-scoped backend auth token changed. Carries a token minted for
230
+ * this packageName only; it is never a Core or runtime access token.
231
+ */
232
+ AUTH_UPDATE = "miniapp_auth_update",
233
+
234
+ /** Reply to PING. SDK auto-handles this; developers never see it. */
235
+ PONG = "miniapp_pong",
236
+
237
+ /**
238
+ * Host → target: deliver an action call (from another miniapp's
239
+ * session.actions.invoke) to this miniapp's session.actions.handle handler.
240
+ * Carries {callId, actionId, params, callerPackageName}. The SDK runs the
241
+ * handler and replies with an ACTION_RESULT request keyed by callId.
242
+ */
243
+ ACTION_CALL = "miniapp_action_call",
244
+
245
+ /**
246
+ * Push: phone is about to tear down the miniapp's session. Gives the SDK
247
+ * a brief window (~50ms grace on the phone side) to fire one last
248
+ * `sendOneShot` before the transport closes — used to flush final
249
+ * cleanup like `display.render([])`. Synchronous handlers only.
250
+ */
251
+ WILL_DISCONNECT = "miniapp_will_disconnect",
252
+
253
+ /** Async error not tied to a specific request. */
254
+ ERROR = "miniapp_error",
255
+ }
256
+
257
+ // ============================================================================
258
+ // Stream types a miniapp can subscribe to
259
+ // ============================================================================
260
+
261
+ export enum MiniappStreamType {
262
+ // Hardware / input events
263
+ BUTTON_PRESS = "button_press",
264
+ TOUCH_EVENT = "touch_event",
265
+ HEAD_POSITION = "head_position",
266
+ /**
267
+ * Raw accelerometer reading from the glasses IMU — `{x, y, z}` in g, plus a
268
+ * timestamp. G2 only today. A richer combined IMU stream (accel + gyro +
269
+ * magnetometer) is future work; this is the single-sensor precursor.
270
+ */
271
+ ACCEL_DATA = "accel_data",
272
+
273
+ // Status
274
+ GLASSES_BATTERY = "glasses_battery",
275
+ PHONE_BATTERY = "phone_battery",
276
+ GLASSES_CONNECTION = "glasses_connection",
277
+ /** Glasses Wi-Fi state (connected/ssid). Glasses with Wi-Fi only; needed for streaming. */
278
+ GLASSES_WIFI = "glasses_wifi",
279
+
280
+ // Speech / audio (cloud or local)
281
+ TRANSCRIPTION = "transcription", // language variant: "transcription:en-US"
282
+ TRANSLATION = "translation", // language variant: "translation:en-US"
283
+ AUDIO_CHUNK = "audio_chunk",
284
+ VAD = "vad",
285
+
286
+ // Phone sensors
287
+ LOCATION_UPDATE = "location_update",
288
+ /** Compass heading in degrees (0=N, 90=E). Android only. */
289
+ HEADING_UPDATE = "heading_update",
290
+ /** Turn-by-turn navigation event (maneuver / rerouting / arrived / error). */
291
+ NAVIGATION_UPDATE = "navigation_update",
292
+ /** Active navigation route polyline — full path, fired once per route build. */
293
+ NAVIGATION_ROUTE = "navigation_route",
294
+ PHONE_NOTIFICATION = "phone_notification",
295
+ /**
296
+ * A previously-posted notification was dismissed by the user.
297
+ *
298
+ * Android-only today. iOS does not expose dismiss callbacks to apps
299
+ * (Apple privacy restriction); subscribing on iOS succeeds but no events
300
+ * fire. See agents/miniapp-speaker-state-and-notif-dismissed-plan.md.
301
+ */
302
+ PHONE_NOTIFICATION_DISMISSED = "phone_notification_dismissed",
303
+ CALENDAR_EVENT = "calendar_event",
304
+
305
+ // Photos, streaming
306
+ PHOTO_TAKEN = "photo_taken",
307
+ STREAM_STATUS = "stream_status",
308
+ }
309
+
310
+ // ============================================================================
311
+ // Error codes
312
+ // ============================================================================
313
+
314
+ export enum MiniappErrorCode {
315
+ /** Request arguments failed host-side validation. */
316
+ INVALID_ARGUMENT = "INVALID_ARGUMENT",
317
+
318
+ /** The miniapp subscribed to a stream whose required permission wasn't in its manifest. */
319
+ PERMISSION_NOT_DECLARED = "PERMISSION_NOT_DECLARED",
320
+
321
+ /** Request routed to a method that isn't supported yet. */
322
+ NOT_IMPLEMENTED = "NOT_IMPLEMENTED",
323
+
324
+ /** Request timed out or the session was torn down before it could complete. */
325
+ REQUEST_ABORTED = "REQUEST_ABORTED",
326
+
327
+ /** Phone-side code path threw. Check `message`. */
328
+ INTERNAL = "INTERNAL",
329
+
330
+ /** Cloud TTS returned a non-2xx for a SPEAK request. */
331
+ TTS_TEXT_TOO_LONG = "TTS_TEXT_TOO_LONG",
332
+ TTS_INVALID_VOICE = "TTS_INVALID_VOICE",
333
+ TTS_UPSTREAM_ERROR = "TTS_UPSTREAM_ERROR",
334
+
335
+ /** Not connected / pre-ACK and transport closed. */
336
+ NOT_CONNECTED = "NOT_CONNECTED",
337
+
338
+ // ----- Inter-miniapp interop -----
339
+ /** Caller is not a system app — interop APIs (list/start/stop/invoke) are SYSTEM-only. */
340
+ NOT_PERMITTED = "NOT_PERMITTED",
341
+ /** Target miniapp is not installed. */
342
+ APP_NOT_FOUND = "APP_NOT_FOUND",
343
+ /** Target miniapp is incompatible with the connected glasses. */
344
+ APP_NOT_COMPATIBLE = "APP_NOT_COMPATIBLE",
345
+ /** Target miniapp does not declare the requested action. */
346
+ ACTION_NOT_FOUND = "ACTION_NOT_FOUND",
347
+ /** Target connected but never registered a handler for the action (within the buffer window). */
348
+ NO_ACTION_HANDLER = "NO_ACTION_HANDLER",
349
+ /** Target failed to wake / complete its CONNECT handshake for an invoke. */
350
+ WAKE_FAILED = "WAKE_FAILED",
351
+ /** Action handler did not return within the caller's timeout. */
352
+ ACTION_TIMEOUT = "ACTION_TIMEOUT",
353
+ /** Action params or result exceeded the 256 KB size cap. */
354
+ PAYLOAD_TOO_LARGE = "PAYLOAD_TOO_LARGE",
355
+
356
+ // ----- Blob storage / recorder -----
357
+ /** No blob with the given id in this miniapp's namespace. */
358
+ BLOB_NOT_FOUND = "BLOB_NOT_FOUND",
359
+ /** Writing this blob would exceed the per-app blob quota. */
360
+ BLOB_QUOTA_EXCEEDED = "BLOB_QUOTA_EXCEEDED",
361
+ /** Blob is larger than the requested in-memory read can hold. */
362
+ BLOB_TOO_LARGE = "BLOB_TOO_LARGE",
363
+ /** Write/read handle is unknown, already settled, or belongs to another app. */
364
+ BLOB_HANDLE_INVALID = "BLOB_HANDLE_INVALID",
365
+ /** Filesystem write failed (out of disk, permissions, etc.). */
366
+ BLOB_WRITE_FAILED = "BLOB_WRITE_FAILED",
367
+ /** `blob.setFromUrl` could not download the URL (network / non-2xx). */
368
+ BLOB_DOWNLOAD_FAILED = "BLOB_DOWNLOAD_FAILED",
369
+ /** `blob.importFile` failed (not the user cancelling — that resolves to null). */
370
+ BLOB_IMPORT_FAILED = "BLOB_IMPORT_FAILED",
371
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * @fileoverview MentraProvider — optional root provider for miniapp apps.
3
+ *
4
+ * Opt-in conveniences that would otherwise require boilerplate in every
5
+ * miniapp. Currently:
6
+ * - Keeps `<html class="dark">` in sync with the host's color scheme so the
7
+ * shared theme CSS switches automatically.
8
+ *
9
+ * Usage:
10
+ * createRoot(root).render(
11
+ * <MentraProvider>
12
+ * <App />
13
+ * </MentraProvider>
14
+ * )
15
+ *
16
+ * Each convenience is controllable via props so miniapps that manage these
17
+ * things themselves can opt out without forking the provider.
18
+ */
19
+
20
+ import {type ReactNode} from "react"
21
+
22
+ import {useColorScheme} from "./useColorScheme"
23
+
24
+ export interface MentraProviderProps {
25
+ children: ReactNode
26
+ /**
27
+ * Toggle `document.documentElement.classList` "dark" to match the host's
28
+ * current color scheme. The toggle runs synchronously during render so
29
+ * children paint with the correct class on first mount — no flash.
30
+ *
31
+ * Default: true. Set to false if your app owns the `dark` class itself
32
+ * (e.g. you integrate a theming library like next-themes).
33
+ */
34
+ syncColorScheme?: boolean
35
+ }
36
+
37
+ export function MentraProvider({children, syncColorScheme = true}: MentraProviderProps) {
38
+ const scheme = useColorScheme()
39
+
40
+ // Runs during render — before children paint, before effects fire.
41
+ if (syncColorScheme && typeof document !== "undefined") {
42
+ const el = document.documentElement
43
+ const shouldBeDark = scheme === "dark"
44
+ if (el.classList.contains("dark") !== shouldBeDark) {
45
+ el.classList.toggle("dark", shouldBeDark)
46
+ }
47
+ }
48
+
49
+ return <>{children}</>
50
+ }
@@ -0,0 +1,122 @@
1
+ /**
2
+ * @fileoverview MiniappHeader — drop-in header component that aligns with
3
+ * the host's floating capsule menu.
4
+ *
5
+ * The header has three slots: `left`, `title`, and `right`. Content auto-
6
+ * respects the safe area and leaves room for the capsule menu on the far
7
+ * top-right. Typical usage:
8
+ *
9
+ * <MiniappHeader
10
+ * title="My Miniapp"
11
+ * left={<BackButton onClick={goBack} />}
12
+ * right={<Badge>Connected</Badge>}
13
+ * />
14
+ *
15
+ * If `title` is a string it renders as a semantic <h1>. Pass a ReactNode if
16
+ * you need custom styling. The component itself is unstyled beyond the
17
+ * layout — use `className` or `style` for theming.
18
+ */
19
+
20
+ import type {CSSProperties, ReactNode} from "react"
21
+
22
+ import {useCapsuleHeaderStyle, type UseCapsuleHeaderStyleOptions} from "./useCapsuleHeaderStyle"
23
+
24
+ export interface MiniappHeaderProps extends UseCapsuleHeaderStyleOptions {
25
+ /** Title — string renders as <h1>; pass a node for custom markup. */
26
+ title?: ReactNode
27
+ /** Left slot, typically a back button or logo. Overrides onBack if both set. */
28
+ left?: ReactNode
29
+ /**
30
+ * Shortcut: when provided, renders a back chevron in the left slot that
31
+ * calls this handler. Ignored if `left` is explicitly set.
32
+ */
33
+ onBack?: () => void
34
+ /** Right slot, typically a badge or action buttons. Sits to the left of the capsule. */
35
+ right?: ReactNode
36
+ /** Custom className applied to the header element. */
37
+ className?: string
38
+ /** Inline style overrides merged over the computed layout style. */
39
+ style?: CSSProperties
40
+ /**
41
+ * When true, adds a 8px spacer <div> below the header so your next
42
+ * content doesn't sit flush against it. Default true.
43
+ */
44
+ bottomSpacer?: boolean
45
+ }
46
+
47
+ function BackChevron({onBack}: {onBack: () => void}): ReactNode {
48
+ return (
49
+ <button
50
+ type="button"
51
+ onClick={onBack}
52
+ aria-label="Back"
53
+ style={{
54
+ display: "inline-flex",
55
+ alignItems: "center",
56
+ justifyContent: "center",
57
+ width: 32,
58
+ height: 32,
59
+ marginLeft: -8,
60
+ padding: 0,
61
+ border: "none",
62
+ background: "transparent",
63
+ color: "inherit",
64
+ cursor: "pointer",
65
+ borderRadius: 8,
66
+ }}>
67
+ <svg width="22" height="22" viewBox="0 0 24 24" fill="none" aria-hidden="true">
68
+ <path
69
+ d="M15 18l-6-6 6-6"
70
+ stroke="currentColor"
71
+ strokeWidth="2"
72
+ strokeLinecap="round"
73
+ strokeLinejoin="round"
74
+ />
75
+ </svg>
76
+ </button>
77
+ )
78
+ }
79
+
80
+ export function MiniappHeader({
81
+ title,
82
+ left,
83
+ onBack,
84
+ right,
85
+ className,
86
+ style,
87
+ bottomSpacer = true,
88
+ ...styleOptions
89
+ }: MiniappHeaderProps): ReactNode {
90
+ const computedStyle = useCapsuleHeaderStyle(styleOptions)
91
+ const resolvedLeft = left ?? (onBack ? <BackChevron onBack={onBack} /> : null)
92
+
93
+ return (
94
+ <>
95
+ <header className={className} style={{...computedStyle, ...style}}>
96
+ <div style={{display: "flex", alignItems: "center", gap: 10, minWidth: 0, flex: 1}}>
97
+ {resolvedLeft}
98
+ {typeof title === "string" ? (
99
+ <h1
100
+ style={{
101
+ fontSize: 18,
102
+ fontWeight: 600,
103
+ lineHeight: 1,
104
+ margin: 0,
105
+ whiteSpace: "nowrap",
106
+ overflow: "hidden",
107
+ textOverflow: "ellipsis",
108
+ }}>
109
+ {title}
110
+ </h1>
111
+ ) : (
112
+ title
113
+ )}
114
+ </div>
115
+ {right ? (
116
+ <div style={{display: "flex", alignItems: "center", gap: 8, flexShrink: 0}}>{right}</div>
117
+ ) : null}
118
+ </header>
119
+ {bottomSpacer ? <div style={{height: 8, flexShrink: 0}} /> : null}
120
+ </>
121
+ )
122
+ }
@@ -0,0 +1,12 @@
1
+ export {useSafeArea} from "./useSafeArea"
2
+ export type {UseSafeAreaResult} from "./useSafeArea"
3
+ export {useColorScheme} from "./useColorScheme"
4
+ export {useCapabilities} from "./useCapabilities"
5
+ export {useConnected} from "./useConnected"
6
+ export {useCapsuleHeaderStyle} from "./useCapsuleHeaderStyle"
7
+ export type {UseCapsuleHeaderStyleOptions} from "./useCapsuleHeaderStyle"
8
+ export {MiniappHeader} from "./MiniappHeader"
9
+ export type {MiniappHeaderProps} from "./MiniappHeader"
10
+ export {MentraProvider} from "./MentraProvider"
11
+ export type {MentraProviderProps} from "./MentraProvider"
12
+ export {useRpc, type RpcCallable} from "./useRpc"
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @fileoverview useCapabilities — React hook for the connected glasses'
3
+ * capability profile.
4
+ *
5
+ * The glasses `GlassesCapabilities` profile is *background-only* state: it
6
+ * arrives on the background `MiniappSession` (CONNECT_ACK / CAPABILITIES_UPDATE)
7
+ * and is never injected into the UI WebView, so there is no WebView-side source
8
+ * for it — this hook always returns `null`.
9
+ *
10
+ * If a UI page needs glasses capabilities, relay them from the background half
11
+ * over an app channel: read `session.capabilities` in a `session.ui.onOpen`
12
+ * handler, `session.ui.send("caps", ...)`, then read it in the UI with
13
+ * `mentra.on("caps", ...)`. See the example miniapp's `captions:snapshot`
14
+ * channel for the pattern.
15
+ *
16
+ * IMPORTANT: this hook must NOT construct a `MiniappSession`. That is the
17
+ * *background* (JSContext) API; inside a UI WebView its `CONNECT` never gets an
18
+ * ACK from the host's UI router and `session.connect()` times out
19
+ * ("CONNECT_ACK timeout") — the original reason this hook was rewritten.
20
+ *
21
+ * (Note: `window.MentraOS.capabilities` is a different thing — host *feature*
22
+ * flags like "share" / "open_url", not the glasses hardware profile.)
23
+ */
24
+
25
+ import {type GlassesCapabilities} from "../session"
26
+
27
+ export function useCapabilities(): GlassesCapabilities | null {
28
+ return null
29
+ }
@@ -0,0 +1,54 @@
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
+
16
+ import type {CSSProperties} from "react"
17
+
18
+ import {useSafeArea} from "./useSafeArea"
19
+
20
+ export interface UseCapsuleHeaderStyleOptions {
21
+ /** Extra left padding beyond the safe area. Default 20px. */
22
+ leftPadding?: number
23
+ /** Extra space between the header content and the capsule menu. Default 16px. */
24
+ rightGap?: number
25
+ /** Fallback header height when no capsule menu is present. Default 32px. */
26
+ fallbackHeight?: number
27
+ /** Fallback top margin when no capsule menu is present. Default 16px. */
28
+ fallbackMarginTop?: number
29
+ }
30
+
31
+ export function useCapsuleHeaderStyle(
32
+ options: UseCapsuleHeaderStyleOptions = {},
33
+ ): CSSProperties {
34
+ const {leftPadding = 20, rightGap = 16, fallbackHeight = 32, fallbackMarginTop = 16} = options
35
+ const {insets, capsuleMenu} = useSafeArea()
36
+
37
+ const height = capsuleMenu?.height ?? fallbackHeight
38
+ const center = capsuleMenu
39
+ ? capsuleMenu.top + capsuleMenu.height / 2 - insets.top
40
+ : fallbackMarginTop + height / 2
41
+ const marginTop = Math.max(0, center - height / 2)
42
+ const paddingRight = capsuleMenu ? capsuleMenu.width + rightGap : leftPadding
43
+
44
+ return {
45
+ display: "flex",
46
+ flexShrink: 0,
47
+ alignItems: "center",
48
+ justifyContent: "space-between",
49
+ paddingLeft: leftPadding,
50
+ paddingRight,
51
+ marginTop,
52
+ height,
53
+ }
54
+ }
@@ -0,0 +1,26 @@
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
+
17
+ import {useState} from "react"
18
+
19
+ import {getMentraOSGlobals, type MiniappColorScheme} from "../globals"
20
+
21
+ export function useColorScheme(): MiniappColorScheme {
22
+ const [scheme] = useState<MiniappColorScheme>(() => {
23
+ return getMentraOSGlobals().colorScheme === "dark" ? "dark" : "light"
24
+ })
25
+ return scheme
26
+ }