@glassly/miniapp 0.3.0-dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (312) hide show
  1. package/README.md +275 -0
  2. package/dist/background/index.d.ts +64 -0
  3. package/dist/background/index.d.ts.map +1 -0
  4. package/dist/background/index.js +26 -0
  5. package/dist/background/index.js.map +1 -0
  6. package/dist/background/register.d.ts +39 -0
  7. package/dist/background/register.d.ts.map +1 -0
  8. package/dist/background/register.js +72 -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 +60 -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/hardware.d.ts +38 -0
  23. package/dist/hardware.d.ts.map +1 -0
  24. package/dist/hardware.js +31 -0
  25. package/dist/hardware.js.map +1 -0
  26. package/dist/index.d.ts +65 -0
  27. package/dist/index.d.ts.map +1 -0
  28. package/dist/index.js +34 -0
  29. package/dist/index.js.map +1 -0
  30. package/dist/modules/actions.d.ts +81 -0
  31. package/dist/modules/actions.d.ts.map +1 -0
  32. package/dist/modules/actions.js +137 -0
  33. package/dist/modules/actions.js.map +1 -0
  34. package/dist/modules/ai.d.ts +211 -0
  35. package/dist/modules/ai.d.ts.map +1 -0
  36. package/dist/modules/ai.js +117 -0
  37. package/dist/modules/ai.js.map +1 -0
  38. package/dist/modules/auth.d.ts +25 -0
  39. package/dist/modules/auth.d.ts.map +1 -0
  40. package/dist/modules/auth.js +52 -0
  41. package/dist/modules/auth.js.map +1 -0
  42. package/dist/modules/base64.d.ts +16 -0
  43. package/dist/modules/base64.d.ts.map +1 -0
  44. package/dist/modules/base64.js +92 -0
  45. package/dist/modules/base64.js.map +1 -0
  46. package/dist/modules/blob.d.ts +161 -0
  47. package/dist/modules/blob.d.ts.map +1 -0
  48. package/dist/modules/blob.js +277 -0
  49. package/dist/modules/blob.js.map +1 -0
  50. package/dist/modules/camera.d.ts +183 -0
  51. package/dist/modules/camera.d.ts.map +1 -0
  52. package/dist/modules/camera.js +119 -0
  53. package/dist/modules/camera.js.map +1 -0
  54. package/dist/modules/cloud.d.ts +34 -0
  55. package/dist/modules/cloud.d.ts.map +1 -0
  56. package/dist/modules/cloud.js +70 -0
  57. package/dist/modules/cloud.js.map +1 -0
  58. package/dist/modules/dashboard.d.ts +24 -0
  59. package/dist/modules/dashboard.d.ts.map +1 -0
  60. package/dist/modules/dashboard.js +39 -0
  61. package/dist/modules/dashboard.js.map +1 -0
  62. package/dist/modules/display.d.ts +167 -0
  63. package/dist/modules/display.d.ts.map +1 -0
  64. package/dist/modules/display.js +83 -0
  65. package/dist/modules/display.js.map +1 -0
  66. package/dist/modules/events.d.ts +178 -0
  67. package/dist/modules/events.d.ts.map +1 -0
  68. package/dist/modules/events.js +168 -0
  69. package/dist/modules/events.js.map +1 -0
  70. package/dist/modules/glasses.d.ts +36 -0
  71. package/dist/modules/glasses.d.ts.map +1 -0
  72. package/dist/modules/glasses.js +52 -0
  73. package/dist/modules/glasses.js.map +1 -0
  74. package/dist/modules/heading.d.ts +16 -0
  75. package/dist/modules/heading.d.ts.map +1 -0
  76. package/dist/modules/heading.js +20 -0
  77. package/dist/modules/heading.js.map +1 -0
  78. package/dist/modules/imu.d.ts +31 -0
  79. package/dist/modules/imu.d.ts.map +1 -0
  80. package/dist/modules/imu.js +40 -0
  81. package/dist/modules/imu.js.map +1 -0
  82. package/dist/modules/input.d.ts +34 -0
  83. package/dist/modules/input.d.ts.map +1 -0
  84. package/dist/modules/input.js +50 -0
  85. package/dist/modules/input.js.map +1 -0
  86. package/dist/modules/keys.d.ts +30 -0
  87. package/dist/modules/keys.d.ts.map +1 -0
  88. package/dist/modules/keys.js +37 -0
  89. package/dist/modules/keys.js.map +1 -0
  90. package/dist/modules/languages.d.ts +42 -0
  91. package/dist/modules/languages.d.ts.map +1 -0
  92. package/dist/modules/languages.js +57 -0
  93. package/dist/modules/languages.js.map +1 -0
  94. package/dist/modules/led.d.ts +35 -0
  95. package/dist/modules/led.d.ts.map +1 -0
  96. package/dist/modules/led.js +39 -0
  97. package/dist/modules/led.js.map +1 -0
  98. package/dist/modules/location.d.ts +27 -0
  99. package/dist/modules/location.d.ts.map +1 -0
  100. package/dist/modules/location.js +35 -0
  101. package/dist/modules/location.js.map +1 -0
  102. package/dist/modules/memory.d.ts +126 -0
  103. package/dist/modules/memory.d.ts.map +1 -0
  104. package/dist/modules/memory.js +141 -0
  105. package/dist/modules/memory.js.map +1 -0
  106. package/dist/modules/mic.d.ts +61 -0
  107. package/dist/modules/mic.d.ts.map +1 -0
  108. package/dist/modules/mic.js +94 -0
  109. package/dist/modules/mic.js.map +1 -0
  110. package/dist/modules/miniapps.d.ts +82 -0
  111. package/dist/modules/miniapps.d.ts.map +1 -0
  112. package/dist/modules/miniapps.js +58 -0
  113. package/dist/modules/miniapps.js.map +1 -0
  114. package/dist/modules/navigation.d.ts +332 -0
  115. package/dist/modules/navigation.d.ts.map +1 -0
  116. package/dist/modules/navigation.js +387 -0
  117. package/dist/modules/navigation.js.map +1 -0
  118. package/dist/modules/permissions.d.ts +58 -0
  119. package/dist/modules/permissions.d.ts.map +1 -0
  120. package/dist/modules/permissions.js +66 -0
  121. package/dist/modules/permissions.js.map +1 -0
  122. package/dist/modules/phone.d.ts +95 -0
  123. package/dist/modules/phone.d.ts.map +1 -0
  124. package/dist/modules/phone.js +110 -0
  125. package/dist/modules/phone.js.map +1 -0
  126. package/dist/modules/pivots/engine.d.ts +169 -0
  127. package/dist/modules/pivots/engine.d.ts.map +1 -0
  128. package/dist/modules/pivots/engine.js +778 -0
  129. package/dist/modules/pivots/engine.js.map +1 -0
  130. package/dist/modules/pivots/geometry.d.ts +84 -0
  131. package/dist/modules/pivots/geometry.d.ts.map +1 -0
  132. package/dist/modules/pivots/geometry.js +371 -0
  133. package/dist/modules/pivots/geometry.js.map +1 -0
  134. package/dist/modules/pivots/instructions.d.ts +139 -0
  135. package/dist/modules/pivots/instructions.d.ts.map +1 -0
  136. package/dist/modules/pivots/instructions.js +281 -0
  137. package/dist/modules/pivots/instructions.js.map +1 -0
  138. package/dist/modules/speaker.d.ts +175 -0
  139. package/dist/modules/speaker.d.ts.map +1 -0
  140. package/dist/modules/speaker.js +249 -0
  141. package/dist/modules/speaker.js.map +1 -0
  142. package/dist/modules/speakers.d.ts +29 -0
  143. package/dist/modules/speakers.d.ts.map +1 -0
  144. package/dist/modules/speakers.js +38 -0
  145. package/dist/modules/speakers.js.map +1 -0
  146. package/dist/modules/storage.d.ts +50 -0
  147. package/dist/modules/storage.d.ts.map +1 -0
  148. package/dist/modules/storage.js +99 -0
  149. package/dist/modules/storage.js.map +1 -0
  150. package/dist/modules/stream.d.ts +133 -0
  151. package/dist/modules/stream.d.ts.map +1 -0
  152. package/dist/modules/stream.js +53 -0
  153. package/dist/modules/stream.js.map +1 -0
  154. package/dist/modules/system.d.ts +71 -0
  155. package/dist/modules/system.d.ts.map +1 -0
  156. package/dist/modules/system.js +65 -0
  157. package/dist/modules/system.js.map +1 -0
  158. package/dist/modules/transcription.d.ts +99 -0
  159. package/dist/modules/transcription.d.ts.map +1 -0
  160. package/dist/modules/transcription.js +126 -0
  161. package/dist/modules/transcription.js.map +1 -0
  162. package/dist/modules/translation.d.ts +65 -0
  163. package/dist/modules/translation.d.ts.map +1 -0
  164. package/dist/modules/translation.js +121 -0
  165. package/dist/modules/translation.js.map +1 -0
  166. package/dist/modules/ui.d.ts +186 -0
  167. package/dist/modules/ui.d.ts.map +1 -0
  168. package/dist/modules/ui.js +289 -0
  169. package/dist/modules/ui.js.map +1 -0
  170. package/dist/protocol.d.ts +384 -0
  171. package/dist/protocol.d.ts.map +1 -0
  172. package/dist/protocol.js +413 -0
  173. package/dist/protocol.js.map +1 -0
  174. package/dist/react/MiniappHeader.d.ts +44 -0
  175. package/dist/react/MiniappHeader.d.ts.map +1 -0
  176. package/dist/react/MiniappHeader.js +32 -0
  177. package/dist/react/MiniappHeader.js.map +1 -0
  178. package/dist/react/MiniappProvider.d.ts +33 -0
  179. package/dist/react/MiniappProvider.d.ts.map +1 -0
  180. package/dist/react/MiniappProvider.js +15 -0
  181. package/dist/react/MiniappProvider.js.map +1 -0
  182. package/dist/react/capsuleHeaderLayout.d.ts +3 -0
  183. package/dist/react/capsuleHeaderLayout.d.ts.map +1 -0
  184. package/dist/react/capsuleHeaderLayout.js +5 -0
  185. package/dist/react/capsuleHeaderLayout.js.map +1 -0
  186. package/dist/react/index.d.ts +13 -0
  187. package/dist/react/index.d.ts.map +1 -0
  188. package/dist/react/index.js +9 -0
  189. package/dist/react/index.js.map +1 -0
  190. package/dist/react/useCapabilities.d.ts +26 -0
  191. package/dist/react/useCapabilities.d.ts.map +1 -0
  192. package/dist/react/useCapabilities.js +27 -0
  193. package/dist/react/useCapabilities.js.map +1 -0
  194. package/dist/react/useCapsuleHeaderStyle.d.ts +27 -0
  195. package/dist/react/useCapsuleHeaderStyle.d.ts.map +1 -0
  196. package/dist/react/useCapsuleHeaderStyle.js +39 -0
  197. package/dist/react/useCapsuleHeaderStyle.js.map +1 -0
  198. package/dist/react/useColorScheme.d.ts +18 -0
  199. package/dist/react/useColorScheme.d.ts.map +1 -0
  200. package/dist/react/useColorScheme.js +24 -0
  201. package/dist/react/useColorScheme.js.map +1 -0
  202. package/dist/react/useConnected.d.ts +17 -0
  203. package/dist/react/useConnected.d.ts.map +1 -0
  204. package/dist/react/useConnected.js +39 -0
  205. package/dist/react/useConnected.js.map +1 -0
  206. package/dist/react/useRpc.d.ts +29 -0
  207. package/dist/react/useRpc.d.ts.map +1 -0
  208. package/dist/react/useRpc.js +82 -0
  209. package/dist/react/useRpc.js.map +1 -0
  210. package/dist/react/useSafeArea.d.ts +21 -0
  211. package/dist/react/useSafeArea.d.ts.map +1 -0
  212. package/dist/react/useSafeArea.js +22 -0
  213. package/dist/react/useSafeArea.js.map +1 -0
  214. package/dist/session.d.ts +355 -0
  215. package/dist/session.d.ts.map +1 -0
  216. package/dist/session.js +688 -0
  217. package/dist/session.js.map +1 -0
  218. package/dist/sub-path-types.test-d.d.ts +40 -0
  219. package/dist/sub-path-types.test-d.d.ts.map +1 -0
  220. package/dist/sub-path-types.test-d.js +37 -0
  221. package/dist/sub-path-types.test-d.js.map +1 -0
  222. package/dist/transport/auto.d.ts +35 -0
  223. package/dist/transport/auto.d.ts.map +1 -0
  224. package/dist/transport/auto.js +124 -0
  225. package/dist/transport/auto.js.map +1 -0
  226. package/dist/transport/dispatch.d.ts +43 -0
  227. package/dist/transport/dispatch.d.ts.map +1 -0
  228. package/dist/transport/dispatch.js +91 -0
  229. package/dist/transport/dispatch.js.map +1 -0
  230. package/dist/transport/local-socket.d.ts +28 -0
  231. package/dist/transport/local-socket.d.ts.map +1 -0
  232. package/dist/transport/local-socket.js +80 -0
  233. package/dist/transport/local-socket.js.map +1 -0
  234. package/dist/transport/mock.d.ts +54 -0
  235. package/dist/transport/mock.d.ts.map +1 -0
  236. package/dist/transport/mock.js +210 -0
  237. package/dist/transport/mock.js.map +1 -0
  238. package/dist/transport/postmessage.d.ts +36 -0
  239. package/dist/transport/postmessage.d.ts.map +1 -0
  240. package/dist/transport/postmessage.js +78 -0
  241. package/dist/transport/postmessage.js.map +1 -0
  242. package/dist/transport/types.d.ts +25 -0
  243. package/dist/transport/types.d.ts.map +1 -0
  244. package/dist/transport/types.js +11 -0
  245. package/dist/transport/types.js.map +1 -0
  246. package/dist/ui/index.d.ts +107 -0
  247. package/dist/ui/index.d.ts.map +1 -0
  248. package/dist/ui/index.js +32 -0
  249. package/dist/ui/index.js.map +1 -0
  250. package/package.json +84 -0
  251. package/src/background/index.ts +177 -0
  252. package/src/background/register.ts +89 -0
  253. package/src/dev-reload.ts +59 -0
  254. package/src/envelope.ts +54 -0
  255. package/src/globals.ts +62 -0
  256. package/src/hardware.ts +40 -0
  257. package/src/index.ts +216 -0
  258. package/src/modules/actions.ts +189 -0
  259. package/src/modules/ai.ts +281 -0
  260. package/src/modules/auth.ts +68 -0
  261. package/src/modules/base64.ts +87 -0
  262. package/src/modules/blob.ts +341 -0
  263. package/src/modules/camera.ts +258 -0
  264. package/src/modules/cloud.ts +94 -0
  265. package/src/modules/dashboard.ts +51 -0
  266. package/src/modules/display.ts +207 -0
  267. package/src/modules/events.ts +318 -0
  268. package/src/modules/glasses.ts +58 -0
  269. package/src/modules/heading.ts +23 -0
  270. package/src/modules/imu.ts +44 -0
  271. package/src/modules/input.ts +66 -0
  272. package/src/modules/keys.ts +46 -0
  273. package/src/modules/languages.ts +72 -0
  274. package/src/modules/led.ts +61 -0
  275. package/src/modules/location.ts +39 -0
  276. package/src/modules/memory.ts +224 -0
  277. package/src/modules/mic.ts +103 -0
  278. package/src/modules/miniapps.ts +103 -0
  279. package/src/modules/navigation.ts +674 -0
  280. package/src/modules/permissions.ts +83 -0
  281. package/src/modules/phone.ts +155 -0
  282. package/src/modules/pivots/engine.ts +863 -0
  283. package/src/modules/pivots/geometry.ts +409 -0
  284. package/src/modules/pivots/instructions.ts +341 -0
  285. package/src/modules/speaker.ts +347 -0
  286. package/src/modules/speakers.ts +40 -0
  287. package/src/modules/storage.ts +109 -0
  288. package/src/modules/stream.ts +168 -0
  289. package/src/modules/system.ts +113 -0
  290. package/src/modules/transcription.ts +180 -0
  291. package/src/modules/translation.ts +156 -0
  292. package/src/modules/ui.ts +481 -0
  293. package/src/protocol.ts +475 -0
  294. package/src/react/MiniappHeader.tsx +114 -0
  295. package/src/react/MiniappProvider.tsx +50 -0
  296. package/src/react/capsuleHeaderLayout.ts +11 -0
  297. package/src/react/index.ts +12 -0
  298. package/src/react/useCapabilities.ts +29 -0
  299. package/src/react/useCapsuleHeaderStyle.ts +55 -0
  300. package/src/react/useColorScheme.ts +26 -0
  301. package/src/react/useConnected.ts +47 -0
  302. package/src/react/useRpc.ts +103 -0
  303. package/src/react/useSafeArea.ts +36 -0
  304. package/src/session.ts +969 -0
  305. package/src/sub-path-types.test-d.ts +60 -0
  306. package/src/transport/auto.ts +143 -0
  307. package/src/transport/dispatch.ts +106 -0
  308. package/src/transport/local-socket.ts +91 -0
  309. package/src/transport/mock.ts +255 -0
  310. package/src/transport/postmessage.ts +95 -0
  311. package/src/transport/types.ts +26 -0
  312. package/src/ui/index.ts +129 -0
@@ -0,0 +1,475 @@
1
+ /**
2
+ * @fileoverview Wire protocol for @glassly/miniapp.
3
+ *
4
+ * Fresh miniapp-naming enum values. No legacy tpa_/app_/applet_ prefixes.
5
+ * These values are the contract between @glassly/miniapp (running in a WebView)
6
+ * and LocalMiniappRuntime (running on the phone).
7
+ *
8
+ * IMPORTANT: This file has NO runtime dependency on @glassly/sdk. The cloud SDK's
9
+ * wire protocol enums live in @glassly/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
+ /**
38
+ * Feed the device's firmware-rendered navigation UI (capability
39
+ * `hasNativeNavigation`): structured turn-by-turn card fields and
40
+ * pre-rendered map bitmaps. Only accepted while a trip is active.
41
+ */
42
+ NATIVE_NAV = "miniapp_native_nav",
43
+
44
+ /** Play an arbitrary audio URL through the phone's audio playback service. */
45
+ PLAY_AUDIO = "miniapp_play_audio",
46
+
47
+ /** Stop any audio playback this miniapp initiated. */
48
+ STOP_AUDIO = "miniapp_stop_audio",
49
+
50
+ /** Speak text via cloud TTS — phone constructs the URL. */
51
+ SPEAK = "miniapp_speak",
52
+
53
+ /**
54
+ * Live PCM output stream to the phone's audio playback service
55
+ * (speaker.createStream). OPEN provisions a native chunk player; WRITE
56
+ * appends base64 PCM (replies with {bufferedMs} for backpressure); CLOSE
57
+ * drains and finishes; ABORT drops immediately.
58
+ */
59
+ SPEAKER_STREAM_OPEN = "miniapp_speaker_stream_open",
60
+ SPEAKER_STREAM_WRITE = "miniapp_speaker_stream_write",
61
+ SPEAKER_STREAM_CLOSE = "miniapp_speaker_stream_close",
62
+ SPEAKER_STREAM_ABORT = "miniapp_speaker_stream_abort",
63
+
64
+ /** Control the glasses RGB LED. */
65
+ RGB_LED = "miniapp_rgb_led",
66
+
67
+ /** One-shot location poll. */
68
+ LOCATION_POLL = "miniapp_location_poll",
69
+
70
+ /** Read a bounded snapshot of phone calendar events. */
71
+ CALENDAR_LIST_EVENTS = "miniapp_calendar_list_events",
72
+
73
+ /** Start a turn-by-turn navigation trip. Android only. */
74
+ NAVIGATION_START = "miniapp_navigation_start",
75
+ /** Stop the active navigation trip (if any). */
76
+ NAVIGATION_STOP = "miniapp_navigation_stop",
77
+ /** Dev-only: nudge the simulator off-route to test rerouting. Android sim only. */
78
+ NAVIGATION_DEVIATE = "miniapp_navigation_deviate",
79
+ /** Dev-only: lock simulated locations to the wrong sidewalk for pivot-trigger testing. */
80
+ NAVIGATION_SET_WRONG_SIDEWALK = "miniapp_navigation_set_wrong_sidewalk",
81
+ /** Dev-only: take over the simulator and walk a polyline with crossings stripped. */
82
+ NAVIGATION_SET_SKIP_CROSSINGS = "miniapp_navigation_set_skip_crossings",
83
+ /** Snapshot of the active trip (or null). Lets a miniapp opening mid-trip hydrate. */
84
+ NAVIGATION_GET_STATE = "miniapp_navigation_get_state",
85
+ /** Compute a route without starting a trip. Replaces hand-rolled Directions calls. */
86
+ NAVIGATION_COMPUTE_ROUTE = "miniapp_navigation_compute_route",
87
+ /** Reverse-geocode a coordinate to a short road name + full formatted
88
+ * address. `road` backs the engine's fallback for pivots whose Routes-API
89
+ * instruction didn't include a parseable road; `address` backs UI labels for
90
+ * dropped pins / POI taps. Resolved in the v2 cloud maps service (Mapbox
91
+ * today) via the host bridge — the miniapp never holds a maps token. */
92
+ NAVIGATION_REVERSE_GEOCODE = "miniapp_navigation_reverse_geocode",
93
+ /** Type-ahead place search (autocomplete). Resolved in the v2 cloud maps
94
+ * service (Mapbox Search Box today) via the host bridge — the miniapp never
95
+ * holds a maps token. Pairs with NAVIGATION_PLACE_DETAILS via a sessionToken. */
96
+ NAVIGATION_PLACE_AUTOCOMPLETE = "miniapp_navigation_place_autocomplete",
97
+ /** Resolve an autocomplete suggestion (placeId + sessionToken) to coordinates,
98
+ * in the v2 cloud maps service via the host bridge. */
99
+ NAVIGATION_PLACE_DETAILS = "miniapp_navigation_place_details",
100
+ /** Request nav permission up-front so start() doesn't have to (no dialog under Mapbox). */
101
+ NAVIGATION_REQUEST_PERMISSION = "miniapp_navigation_request_permission",
102
+
103
+ /**
104
+ * Read a user-supplied provider API key (Settings > API Keys) by provider
105
+ * name. Requires the API_KEYS manifest permission; the host only serves an
106
+ * allowlisted provider set (see KeysModule) — notably the Soniox key is
107
+ * excluded. Keys are device-local; the value never transits any server.
108
+ */
109
+ KEYS_GET = "miniapp_keys_get",
110
+
111
+ /**
112
+ * Run one LLM completion turn through the platform. Requires the AI manifest
113
+ * permission. The host routes to the cloud LLM service, which picks the
114
+ * provider and pays with the platform key — or with the user's own key when
115
+ * they've saved one for that provider (Settings > API Keys), in which case
116
+ * the call isn't metered against their plan.
117
+ *
118
+ * Single-shot or a client-side tool loop: when the model wants a tool run,
119
+ * the result comes back with stopReason "tool_use" and the calls to execute;
120
+ * append the answers and call again. The `webSearch` flag grants the
121
+ * provider's own server-side search tool; other provider server-side tools
122
+ * (Anthropic code_execution / Files API) and streaming are deliberately not
123
+ * exposed — see cloud-v2/packages/protocol/src/llm.ts.
124
+ */
125
+ AI_COMPLETE = "miniapp_ai_complete",
126
+ AI_GENERATE = "miniapp_ai_generate",
127
+
128
+ /** Phone-local simple storage. */
129
+ STORAGE_GET = "miniapp_storage_get",
130
+ STORAGE_SET = "miniapp_storage_set",
131
+ STORAGE_DELETE = "miniapp_storage_delete",
132
+ STORAGE_LIST = "miniapp_storage_list",
133
+ STORAGE_CLEAR = "miniapp_storage_clear",
134
+ STORAGE_HAS = "miniapp_storage_has",
135
+ STORAGE_GET_ALL = "miniapp_storage_get_all",
136
+ STORAGE_SET_MULTIPLE = "miniapp_storage_set_multiple",
137
+ STORAGE_FLUSH = "miniapp_storage_flush",
138
+
139
+ /**
140
+ * Shared user-level memory timeline (transcript lines + notes + hourly
141
+ * summaries), stored host-side and scoped to the USER — not to this
142
+ * miniapp's storage namespace. Requires the MEMORY manifest permission.
143
+ * The user manages the same timeline in Settings > Memory.
144
+ */
145
+ MEMORY_APPEND_LINE = "miniapp_memory_append_line",
146
+ MEMORY_ADD_NOTE = "miniapp_memory_add_note",
147
+ MEMORY_REMOVE_ENTRY = "miniapp_memory_remove_entry",
148
+ MEMORY_REMOVE_SCOPE = "miniapp_memory_remove_scope",
149
+ MEMORY_SESSION_LIST = "miniapp_memory_session_list",
150
+ MEMORY_QUERY = "miniapp_memory_query",
151
+ MEMORY_WINDOW = "miniapp_memory_window",
152
+ MEMORY_EXPORT_TEXT = "miniapp_memory_export_text",
153
+ MEMORY_SUMMARY_ADD = "miniapp_memory_summary_add",
154
+ MEMORY_SUMMARY_LIST = "miniapp_memory_summary_list",
155
+ MEMORY_PENDING_SUMMARY_HOUR = "miniapp_memory_pending_summary_hour",
156
+ MEMORY_CLEAR = "miniapp_memory_clear",
157
+
158
+ /**
159
+ * Resolve an enrolled-speaker id (`spk_…` from TranscriptionData.speakerId)
160
+ * to the user's display name for that speaker. Requires the SPEAKERS
161
+ * manifest permission — names are on-device PII and only cross into a
162
+ * miniapp through this explicit, user-visible gate.
163
+ */
164
+ SPEAKERS_RESOLVE_NAME = "miniapp_speakers_resolve_name",
165
+
166
+ /** Write camera FOV settings. */
167
+ CAMERA_FOV = "miniapp_camera_fov",
168
+
169
+ /** Pre-warm the glasses camera so the next takePhoto() is near-instant. */
170
+ CAMERA_WARM_UP = "miniapp_camera_warm_up",
171
+
172
+ /**
173
+ * Enable/disable raw accelerometer (IMU) streaming on the glasses. The
174
+ * accel stream also auto-enables on subscribe; this is an explicit override
175
+ * for callers who want to control the sensor directly. G2 only today.
176
+ */
177
+ IMU_SET_ENABLED = "miniapp_imu_set_enabled",
178
+
179
+ /** Explicitly enable/disable glasses-side VAD (GX8002). Mirrors the app's mic settings toggle. */
180
+ MIC_SET_VAD_ENABLED = "miniapp_mic_set_vad_enabled",
181
+ /** Explicitly enable/disable the center-mic loudness gate ("Barrier"). */
182
+ MIC_SET_LOUDNESS_GATE_ENABLED = "miniapp_mic_set_loudness_gate_enabled",
183
+
184
+ /**
185
+ * Enable or disable Wi-Fi ADB (wireless debugging) on Mentra Live.
186
+ * SYSTEM-only — host rejects with NOT_PERMITTED for non-system callers.
187
+ */
188
+ SET_WIFI_ADB_STATE = "miniapp_set_wifi_adb_state",
189
+
190
+ /** Share content via the OS share sheet. */
191
+ SHARE = "miniapp_share",
192
+ /** Open a URL in the system browser. */
193
+ OPEN_URL = "miniapp_open_url",
194
+ /** Copy text to the system clipboard. */
195
+ COPY_CLIPBOARD = "miniapp_copy_clipboard",
196
+ /** Download a file (triggers OS share sheet for save location). */
197
+ DOWNLOAD = "miniapp_download",
198
+ /**
199
+ * Open a phone-camera QR scanner overlay. Host must not unmount the miniapp
200
+ * (clearing foreground fires UI_CLOSE and can hang up live sessions).
201
+ */
202
+ SCAN_QR = "miniapp_scan_qr",
203
+
204
+ /**
205
+ * Phone-local persistent binary blob storage, scoped to (userId, packageName).
206
+ * Unlike STORAGE_* (small string KV in MMKV), blobs are arbitrary bytes written
207
+ * to the phone filesystem. Large payloads are moved in chunks (BLOB_WRITE /
208
+ * BLOB_READ) so a single bridge message never carries a multi-MB string.
209
+ */
210
+ BLOB_CREATE = "miniapp_blob_create",
211
+ BLOB_WRITE = "miniapp_blob_write",
212
+ BLOB_COMMIT = "miniapp_blob_commit",
213
+ BLOB_ABORT = "miniapp_blob_abort",
214
+ BLOB_GET = "miniapp_blob_get",
215
+ BLOB_LIST = "miniapp_blob_list",
216
+ BLOB_DELETE = "miniapp_blob_delete",
217
+ BLOB_CLEAR = "miniapp_blob_clear",
218
+ BLOB_USAGE = "miniapp_blob_usage",
219
+ BLOB_OPEN_READ = "miniapp_blob_open_read",
220
+ BLOB_READ = "miniapp_blob_read",
221
+ BLOB_CLOSE_READ = "miniapp_blob_close_read",
222
+ /** Download a URL straight into a blob, host-side (no bytes cross the bridge). */
223
+ BLOB_SET_FROM_URL = "miniapp_blob_set_from_url",
224
+ /** Open the OS file picker and import the chosen file into a blob, host-side. */
225
+ BLOB_IMPORT = "miniapp_blob_import",
226
+ /** Share a stored blob from disk via the OS share sheet (no bytes cross the bridge). */
227
+ BLOB_SHARE = "miniapp_blob_share",
228
+
229
+ /** Phone → miniapp liveness probe. Miniapp SDK auto-replies with PONG. */
230
+ PING = "miniapp_ping",
231
+
232
+ /**
233
+ * Apply transcription configuration (language hints, vocabulary, diarization).
234
+ * Phone forwards to the cloud STT layer. Fire-and-forget; cached client-side
235
+ * so future reconnect logic can re-send.
236
+ */
237
+ TRANSCRIPTION_CONFIG = "miniapp_transcription_config",
238
+
239
+ // ----- Deferred in v1 -----
240
+
241
+ /** Dashboard content update. Noop in v1. */
242
+ DASHBOARD_CONTENT_UPDATE = "miniapp_dashboard_content_update",
243
+
244
+ /** Bring the glasses' native dashboard (OS idle screen) to the foreground. */
245
+ SHOW_NATIVE_DASHBOARD = "miniapp_show_native_dashboard",
246
+
247
+ // ----- Photos, streaming -----
248
+ PHOTO = "miniapp_photo",
249
+ VIDEO_RECORDING_START = "miniapp_video_recording_start",
250
+ VIDEO_RECORDING_STOP = "miniapp_video_recording_stop",
251
+ STREAM_START = "miniapp_stream_start",
252
+ STREAM_STOP = "miniapp_stream_stop",
253
+ MANAGED_STREAM_START = "miniapp_managed_stream_start",
254
+ MANAGED_STREAM_STOP = "miniapp_managed_stream_stop",
255
+
256
+ /** Ask the host to open the glasses Wi-Fi setup flow (mirrors the cloud SDK's requestWifiSetup). */
257
+ REQUEST_WIFI_SETUP = "miniapp_request_wifi_setup",
258
+
259
+ // ----- Inter-miniapp interop -----
260
+ // Lifecycle control (MINIAPPS_*) stays SYSTEM-only; the action layer
261
+ // (ACTIONS_LIST / ACTION_INVOKE) is open to every miniapp, gated per-action
262
+ // by the target's manifest `visibility`.
263
+ /** List installed miniapps (compatibility-filtered, with declared actions). SYSTEM-only. */
264
+ MINIAPPS_LIST = "miniapp_apps_list",
265
+ /** Start another miniapp (user-tap semantics). SYSTEM-only. */
266
+ MINIAPPS_START = "miniapp_apps_start",
267
+ /** Stop another miniapp. SYSTEM-only. */
268
+ MINIAPPS_STOP = "miniapp_apps_stop",
269
+ /** Stop the CALLING miniapp itself. One-shot (no reply) and NOT system-gated. */
270
+ MINIAPPS_STOP_SELF = "miniapp_apps_stop_self",
271
+ /** List every action the caller may invoke across installed miniapps (MCP tools/list analog). */
272
+ ACTIONS_LIST = "miniapp_actions_list",
273
+ /** Invoke a declared action on another miniapp; headless-wakes it if stopped. */
274
+ ACTION_INVOKE = "miniapp_action_invoke",
275
+ /** Target → host: the result of a delivered ACTION_CALL, correlated by callId. */
276
+ ACTION_RESULT = "miniapp_action_result",
277
+ /** Ask the host to stop THIS miniapp (self-close; e.g. after finishing a one-shot action). */
278
+ SYSTEM_EXIT = "miniapp_system_exit",
279
+ }
280
+
281
+ // ============================================================================
282
+ // Phone → miniapp (response or push)
283
+ // ============================================================================
284
+
285
+ export enum MiniappResponseType {
286
+ /** Response to CONNECT carrying userId, packageName, capabilities. */
287
+ CONNECT_ACK = "miniapp_connect_ack",
288
+
289
+ /** Push: a streamed event for a subscribed stream. */
290
+ EVENT = "miniapp_event",
291
+
292
+ /** Response to any request that needs a result (matched by requestId). */
293
+ REQUEST_RESULT = "miniapp_request_result",
294
+
295
+ /** Push: glasses capabilities changed. */
296
+ CAPABILITIES_UPDATE = "miniapp_capabilities_update",
297
+
298
+ /** Push: miniapp's foreground/background state changed. */
299
+ VISIBILITY_CHANGE = "miniapp_visibility_change",
300
+
301
+ /** Push: host color scheme (light/dark) changed. */
302
+ COLOR_SCHEME_CHANGE = "miniapp_color_scheme_change",
303
+
304
+ /**
305
+ * Push: speaker playback state transitioned. Per-miniapp; the runtime sends
306
+ * to the owning miniapp only. Carries {state, errorCode?, errorMessage?,
307
+ * durationMs?}. See SpeakerModule.onStateChange().
308
+ */
309
+ SPEAKER_STATE = "miniapp_speaker_state",
310
+
311
+ /**
312
+ * Push: manifest-declared permissions changed (e.g. dev miniapp re-scanned
313
+ * with updated manifest). Carries a full PermissionRecord. SDK caches it
314
+ * and fires session.permissions.onUpdate handlers.
315
+ */
316
+ PERMISSIONS_UPDATE = "miniapp_permissions_update",
317
+
318
+ /**
319
+ * Push: miniapp-scoped backend auth token changed. Carries a token minted for
320
+ * this packageName only; it is never a Core or runtime access token.
321
+ */
322
+ AUTH_UPDATE = "miniapp_auth_update",
323
+
324
+ /** Reply to PING. SDK auto-handles this; developers never see it. */
325
+ PONG = "miniapp_pong",
326
+
327
+ /**
328
+ * Host → target: deliver an action call (from another miniapp's
329
+ * session.actions.invoke) to this miniapp's session.actions.handle handler.
330
+ * Carries {callId, actionId, params, callerPackageName}. The SDK runs the
331
+ * handler and replies with an ACTION_RESULT request keyed by callId.
332
+ */
333
+ ACTION_CALL = "miniapp_action_call",
334
+
335
+ /**
336
+ * Push: phone is about to tear down the miniapp's session. Gives the SDK
337
+ * a brief window (~50ms grace on the phone side) to fire one last
338
+ * `sendOneShot` before the transport closes — used to flush final
339
+ * cleanup like `display.render([])`. Synchronous handlers only.
340
+ */
341
+ WILL_DISCONNECT = "miniapp_will_disconnect",
342
+
343
+ /** Async error not tied to a specific request. */
344
+ ERROR = "miniapp_error",
345
+ }
346
+
347
+ // ============================================================================
348
+ // Stream types a miniapp can subscribe to
349
+ // ============================================================================
350
+
351
+ export enum MiniappStreamType {
352
+ // Hardware / input events
353
+ BUTTON_PRESS = "button_press",
354
+ TOUCH_EVENT = "touch_event",
355
+ HEAD_POSITION = "head_position",
356
+ /**
357
+ * Raw accelerometer reading from the glasses IMU — `{x, y, z}` in g, plus a
358
+ * timestamp. G2 only today. A richer combined IMU stream (accel + gyro +
359
+ * magnetometer) is future work; this is the single-sensor precursor.
360
+ */
361
+ ACCEL_DATA = "accel_data",
362
+
363
+ // Status
364
+ GLASSES_BATTERY = "glasses_battery",
365
+ PHONE_BATTERY = "phone_battery",
366
+ GLASSES_CONNECTION = "glasses_connection",
367
+ /** Glasses Wi-Fi state (connected/ssid). Glasses with Wi-Fi only; needed for streaming. */
368
+ GLASSES_WIFI = "glasses_wifi",
369
+
370
+ // Speech / audio (cloud or local)
371
+ TRANSCRIPTION = "transcription", // language variant: "transcription:en-US"
372
+ TRANSLATION = "translation", // language variant: "translation:en-US"
373
+ AUDIO_CHUNK = "audio_chunk",
374
+ VAD = "vad",
375
+
376
+ // Phone sensors
377
+ LOCATION_UPDATE = "location_update",
378
+ /** Compass heading in degrees (0=N, 90=E). */
379
+ HEADING_UPDATE = "heading_update",
380
+ /** Turn-by-turn navigation event (maneuver / rerouting / arrived / error). */
381
+ NAVIGATION_UPDATE = "navigation_update",
382
+ /** Active navigation route polyline — full path, fired once per route build. */
383
+ NAVIGATION_ROUTE = "navigation_route",
384
+ PHONE_NOTIFICATION = "phone_notification",
385
+ /**
386
+ * A previously-posted notification was dismissed by the user.
387
+ *
388
+ * Android-only today. iOS does not expose dismiss callbacks to apps
389
+ * (Apple privacy restriction); subscribing on iOS succeeds but no events
390
+ * fire. See agents/miniapp-speaker-state-and-notif-dismissed-plan.md.
391
+ */
392
+ PHONE_NOTIFICATION_DISMISSED = "phone_notification_dismissed",
393
+ // Photos, streaming
394
+ PHOTO_TAKEN = "photo_taken",
395
+ STREAM_STATUS = "stream_status",
396
+ }
397
+
398
+ // ============================================================================
399
+ // Error codes
400
+ // ============================================================================
401
+
402
+ export enum MiniappErrorCode {
403
+ /** Request arguments failed host-side validation. */
404
+ INVALID_ARGUMENT = "INVALID_ARGUMENT",
405
+
406
+ /** The miniapp subscribed to a stream whose required permission wasn't in its manifest. */
407
+ PERMISSION_NOT_DECLARED = "PERMISSION_NOT_DECLARED",
408
+
409
+ /** The required phone OS permission is not currently granted. */
410
+ PERMISSION_DENIED = "PERMISSION_DENIED",
411
+
412
+ /** Request routed to a method that isn't supported yet. */
413
+ NOT_IMPLEMENTED = "NOT_IMPLEMENTED",
414
+
415
+ /** Request timed out or the session was torn down before it could complete. */
416
+ REQUEST_ABORTED = "REQUEST_ABORTED",
417
+
418
+ /** Phone-side code path threw. Check `message`. */
419
+ INTERNAL = "INTERNAL",
420
+
421
+ /**
422
+ * The account's free-tier allowance for this feature (e.g. monthly AI
423
+ * credit) is used up. Not retryable this period; the user can upgrade or
424
+ * the miniapp can fall back to a non-cloud path.
425
+ */
426
+ QUOTA_EXCEEDED = "QUOTA_EXCEEDED",
427
+
428
+ /** Cloud TTS returned a non-2xx for a SPEAK request. */
429
+ TTS_TEXT_TOO_LONG = "TTS_TEXT_TOO_LONG",
430
+ TTS_INVALID_VOICE = "TTS_INVALID_VOICE",
431
+ TTS_UPSTREAM_ERROR = "TTS_UPSTREAM_ERROR",
432
+
433
+ /** `speak({forceLocal: true})` but the on-device offline TTS model isn't downloaded/ready. */
434
+ TTS_LOCAL_UNAVAILABLE = "TTS_LOCAL_UNAVAILABLE",
435
+
436
+ /** Not connected / pre-ACK and transport closed. */
437
+ NOT_CONNECTED = "NOT_CONNECTED",
438
+
439
+ // ----- Inter-miniapp interop -----
440
+ /**
441
+ * Caller is not a system app — SYSTEM-only APIs (interop list/start/stop/invoke,
442
+ * setWifiAdbState) reject with this code.
443
+ */
444
+ NOT_PERMITTED = "NOT_PERMITTED",
445
+ /** Target miniapp is not installed. */
446
+ APP_NOT_FOUND = "APP_NOT_FOUND",
447
+ /** Target miniapp is incompatible with the connected glasses. */
448
+ APP_NOT_COMPATIBLE = "APP_NOT_COMPATIBLE",
449
+ /** Target miniapp does not declare the requested action. */
450
+ ACTION_NOT_FOUND = "ACTION_NOT_FOUND",
451
+ /** Target connected but never registered a handler for the action (within the buffer window). */
452
+ NO_ACTION_HANDLER = "NO_ACTION_HANDLER",
453
+ /** Target failed to wake / complete its CONNECT handshake for an invoke. */
454
+ WAKE_FAILED = "WAKE_FAILED",
455
+ /** Action handler did not return within the caller's timeout. */
456
+ ACTION_TIMEOUT = "ACTION_TIMEOUT",
457
+ /** Action params or result exceeded the 256 KB size cap. */
458
+ PAYLOAD_TOO_LARGE = "PAYLOAD_TOO_LARGE",
459
+
460
+ // ----- Blob storage / recorder -----
461
+ /** No blob with the given id in this miniapp's namespace. */
462
+ BLOB_NOT_FOUND = "BLOB_NOT_FOUND",
463
+ /** Writing this blob would exceed the per-app blob quota. */
464
+ BLOB_QUOTA_EXCEEDED = "BLOB_QUOTA_EXCEEDED",
465
+ /** Blob is larger than the requested in-memory read can hold. */
466
+ BLOB_TOO_LARGE = "BLOB_TOO_LARGE",
467
+ /** Write/read handle is unknown, already settled, or belongs to another app. */
468
+ BLOB_HANDLE_INVALID = "BLOB_HANDLE_INVALID",
469
+ /** Filesystem write failed (out of disk, permissions, etc.). */
470
+ BLOB_WRITE_FAILED = "BLOB_WRITE_FAILED",
471
+ /** `blob.setFromUrl` could not download the URL (network / non-2xx). */
472
+ BLOB_DOWNLOAD_FAILED = "BLOB_DOWNLOAD_FAILED",
473
+ /** `blob.importFile` failed (not the user cancelling — that resolves to null). */
474
+ BLOB_IMPORT_FAILED = "BLOB_IMPORT_FAILED",
475
+ }
@@ -0,0 +1,114 @@
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 d="M15 18l-6-6 6-6" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
69
+ </svg>
70
+ </button>
71
+ )
72
+ }
73
+
74
+ export function MiniappHeader({
75
+ title,
76
+ left,
77
+ onBack,
78
+ right,
79
+ className,
80
+ style,
81
+ bottomSpacer = true,
82
+ ...styleOptions
83
+ }: MiniappHeaderProps): ReactNode {
84
+ const computedStyle = useCapsuleHeaderStyle(styleOptions)
85
+ const resolvedLeft = left ?? (onBack ? <BackChevron onBack={onBack} /> : null)
86
+
87
+ return (
88
+ <>
89
+ <header className={className} style={{...computedStyle, ...style}}>
90
+ <div style={{display: "flex", alignItems: "center", gap: 10, minWidth: 0, flex: 1}}>
91
+ {resolvedLeft}
92
+ {typeof title === "string" ? (
93
+ <h1
94
+ style={{
95
+ fontSize: 18,
96
+ fontWeight: 600,
97
+ lineHeight: 1,
98
+ margin: 0,
99
+ whiteSpace: "nowrap",
100
+ overflow: "hidden",
101
+ textOverflow: "ellipsis",
102
+ }}>
103
+ {title}
104
+ </h1>
105
+ ) : (
106
+ title
107
+ )}
108
+ </div>
109
+ {right ? <div style={{display: "flex", alignItems: "center", gap: 8, flexShrink: 0}}>{right}</div> : null}
110
+ </header>
111
+ {bottomSpacer ? <div style={{height: 8, flexShrink: 0}} /> : null}
112
+ </>
113
+ )
114
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * @fileoverview MiniappProvider — 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
+ * <MiniappProvider>
12
+ * <App />
13
+ * </MiniappProvider>
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 MiniappProviderProps {
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 MiniappProvider({children, syncColorScheme = true}: MiniappProviderProps) {
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,11 @@
1
+ import type {MiniappCapsuleMenuRect} from "../globals"
2
+
3
+ export function getCapsuleHeaderPaddingRight(
4
+ capsuleMenu: MiniappCapsuleMenuRect,
5
+ viewportWidth: number,
6
+ safeAreaRight: number,
7
+ rightGap: number,
8
+ ): number {
9
+ const capsuleOffsetFromContentRight = viewportWidth - capsuleMenu.left - safeAreaRight
10
+ return Math.max(rightGap, capsuleOffsetFromContentRight + rightGap)
11
+ }
@@ -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 {MiniappProvider} from "./MiniappProvider"
11
+ export type {MiniappProviderProps} from "./MiniappProvider"
12
+ export {useRpc, type RpcCallable} from "./useRpc"