@glassly/miniapp 0.1.0-dev.26

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 +24 -0
  23. package/dist/hardware.d.ts.map +1 -0
  24. package/dist/hardware.js +20 -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 +174 -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 +50 -0
  83. package/dist/modules/input.d.ts.map +1 -0
  84. package/dist/modules/input.js +70 -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 +390 -0
  171. package/dist/protocol.d.ts.map +1 -0
  172. package/dist/protocol.js +419 -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 +88 -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 +25 -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 +214 -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 +87 -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 +482 -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,177 @@
1
+ /**
2
+ * @glassly/miniapp/background — background-side SDK entry point.
3
+ *
4
+ * Imported from a miniapp's `src/background/index.ts` to access the
5
+ * per-miniapp `MiniappSession` and its typed `session.*` module
6
+ * wrappers. This is the **always-running JSContext side** of a two-layer
7
+ * miniapp.
8
+ *
9
+ * What's NOT in this entry point:
10
+ * - `glassly` WebView global (UI-only — import from `@glassly/miniapp/ui`).
11
+ * - `MiniappProvider` / React hooks (UI-only).
12
+ * - Any DOM-bound API. The JSContext has no DOM.
13
+ *
14
+ * Importing the wrong sub-path is caught at compile time by the
15
+ * separate type-roots on each `exports` entry.
16
+ */
17
+
18
+ export {MiniappSession, type MiniappSessionOptions} from "../session"
19
+ export {registerMiniapp, type MiniappInitHandler, type TypedMiniappSession} from "./register"
20
+
21
+ // Event / data type re-exports — these are payload shapes a miniapp's
22
+ // background-side handlers consume from session.transcription.on, etc.
23
+ export type {
24
+ TranscriptionData,
25
+ TranslationData,
26
+ ButtonPressData,
27
+ AudioChunkData,
28
+ VadData,
29
+ BatteryData,
30
+ ConnectionData,
31
+ WifiData,
32
+ HeadPositionData,
33
+ AccelData,
34
+ LocationData,
35
+ PhoneNotificationData,
36
+ NotificationDismissedData,
37
+ HeadingData,
38
+ TouchData,
39
+ UnsubscribeFn,
40
+ } from "../modules/events"
41
+ export type {CalendarEvent, CalendarListOptions, CalendarListResult} from "../modules/phone"
42
+
43
+ // Public envelope + protocol types so authors can write strongly-typed
44
+ // glue when they need to fall back to session.sendOneShot / sendRequest.
45
+ export {MiniappRequestType, MiniappResponseType, MiniappStreamType, MiniappErrorCode} from "../protocol"
46
+ export {
47
+ MiniappValidationError,
48
+ SUPPORTED_LANGUAGE_HINTS,
49
+ SUPPORTED_TRANSCRIPTION_LANGUAGES,
50
+ isTranscriptionLanguage,
51
+ } from "../modules/languages"
52
+ export type {LanguageHint, TranscriptionLanguage} from "../modules/languages"
53
+
54
+ // Action handler types — for typing `session.actions.handle(id, fn)` handlers
55
+ // (the registering side lives in the background JSContext). `InvokeOptions` is
56
+ // for system miniapps that call other apps' actions via `session.actions.invoke`.
57
+ export type {ActionContext, ActionHandler, InvokeOptions} from "../modules/actions"
58
+
59
+ // Session module types — useful for typing controller classes or
60
+ // utility helpers that take a session-like dependency.
61
+ export type {DisplayManager} from "../modules/display"
62
+ export type {
63
+ CameraFovPreset,
64
+ CameraFovRequest,
65
+ CameraFovResult,
66
+ CameraModule,
67
+ CameraRoiPosition,
68
+ SetCameraFovOptions,
69
+ } from "../modules/camera"
70
+ export type {
71
+ CloudClientAudioTransport,
72
+ CloudClientConnectionStatus,
73
+ CloudClientStatus,
74
+ CloudModule,
75
+ } from "../modules/cloud"
76
+ export type {DashboardAPI} from "../modules/dashboard"
77
+ export type {GlassesModule} from "../modules/glasses"
78
+ export type {HeadingModule} from "../modules/heading"
79
+ export type {ImuModule} from "../modules/imu"
80
+ export type {InputModule} from "../modules/input"
81
+ export type {LedModule} from "../modules/led"
82
+ export type {LocationModule} from "../modules/location"
83
+ export type {
84
+ MemoryModule,
85
+ MemoryEntry,
86
+ MemoryEntryKind,
87
+ MemoryNoteSource,
88
+ MemoryQuery,
89
+ MemorySession,
90
+ MemorySummary,
91
+ } from "../modules/memory"
92
+ export type {SpeakersModule} from "../modules/speakers"
93
+ export type {MicModule} from "../modules/mic"
94
+ export type {NavigationModule} from "../modules/navigation"
95
+ export type {PermissionsModule} from "../modules/permissions"
96
+ export type {PhoneModule} from "../modules/phone"
97
+ export type {SimpleStorage} from "../modules/storage"
98
+ export {BlobModule, BlobWriter, BlobReader, BLOB_WRITE_CHUNK_BYTES, BLOB_READ_ALL_MAX_BYTES} from "../modules/blob"
99
+ export type {BlobMeta, BlobSetOptions, BlobSetFromUrlOptions, BlobImportOptions} from "../modules/blob"
100
+ export {bytesToBase64, base64ToBytes} from "../modules/base64"
101
+ export type {SpeakerModule} from "../modules/speaker"
102
+ export type {StreamModule} from "../modules/stream"
103
+ export type {SystemModule} from "../modules/system"
104
+ export type {TranscriptionModule} from "../modules/transcription"
105
+ export type {TranslationModule} from "../modules/translation"
106
+ export type {UIModule, UIChannelHandler, UIUnsubscribe} from "../modules/ui"
107
+ export type {Rpc, IsRpc, RpcReq, RpcRes, RpcRequestOptions, RpcHandlerContext} from "../modules/ui"
108
+ export {RpcError, RpcTimeoutError} from "../modules/ui"
109
+
110
+ // Argument enums + option types — for authors writing controllers that pass
111
+ // these into session.* method calls (or that build typed helpers around them).
112
+ // Intentionally NOT re-exported from `@glassly/miniapp/ui` — the WebView half
113
+ // never touches these directly. UI talks to background via glassly.send with
114
+ // the author's own `Channels` registry; background is where these enums show
115
+ // up as method args.
116
+ export type {LedColor, LedControlOptions} from "../modules/led"
117
+ export type {
118
+ ViewType,
119
+ DisplayBreakMode,
120
+ RenderBox,
121
+ RenderElement,
122
+ RenderOptions,
123
+ RenderRectStyle,
124
+ RenderResult,
125
+ RenderTextStyle,
126
+ } from "../modules/display"
127
+ export type {DashboardMode, ShowNativeDashboardResult} from "../modules/dashboard"
128
+ export type {PlayAudioOptions, SpeakOptions, SpeakResult, SpeakerState, SpeakerStateEvent} from "../modules/speaker"
129
+ export type {
130
+ ShareOptions,
131
+ ShareResult,
132
+ DownloadOptions,
133
+ DownloadResult,
134
+ ScanQrOptions,
135
+ ScanQrResult,
136
+ } from "../modules/system"
137
+ export type {TranscriptionConfig, TranscriptionOptions} from "../modules/transcription"
138
+ export type {PermissionErrorEvent} from "../modules/permissions"
139
+ export type {
140
+ AuthUpdatePayload,
141
+ MiniappVisibility,
142
+ PermissionType,
143
+ PermissionRecord,
144
+ GlassesCapabilities,
145
+ ConnectAckPayload,
146
+ MiniappAuthState,
147
+ MiniappRequestError,
148
+ } from "../session"
149
+ export type {AuthFetchOptions, AuthModule} from "../modules/auth"
150
+ export type {MiniappColorScheme} from "../globals"
151
+ // Navigation — exported as a single block since the types reference each other.
152
+ export type {
153
+ LatLng,
154
+ TravelMode,
155
+ ManeuverKind,
156
+ RouteAvoidances,
157
+ NavManeuver,
158
+ NavOffRoute,
159
+ NavRerouting,
160
+ NavArrived,
161
+ NavError,
162
+ NavCancelled,
163
+ NavUpdate,
164
+ NavRoute,
165
+ PivotOptions,
166
+ Pivot,
167
+ PivotEvent,
168
+ NavStep,
169
+ NavigationDev,
170
+ StartNavigationOptions,
171
+ NavState,
172
+ NavPermissionResult,
173
+ ComputeRouteOptions,
174
+ ComputedRouteStep,
175
+ ComputedRoute,
176
+ ComputeRouteResult,
177
+ } from "../modules/navigation"
@@ -0,0 +1,89 @@
1
+ /**
2
+ * registerMiniapp — entry hook for the background JSContext.
3
+ *
4
+ * The GlasslyJS host loads the polyfill (which installs __dispatch /
5
+ * __deliver / timers / fetch / etc.), then evaluates the miniapp's
6
+ * background bundle. After both scripts have evaluated successfully,
7
+ * the host delivers a single `{kind: "init", sessionId}` envelope.
8
+ * The polyfill turns that into a call to `__initCallback(sessionId)`.
9
+ *
10
+ * This module wires that callback to:
11
+ * 1. Construct a `MiniappSession` (DispatchTransport picks itself
12
+ * automatically because `__dispatch` is on globalThis).
13
+ * 2. Call the user-supplied handler synchronously so subscriptions
14
+ * are registered before any host events fan out.
15
+ * 3. Call `session.connect()` so the host receives CONNECT and the
16
+ * first CONNECT_ACK populates `userId`, `capabilities`, etc.
17
+ *
18
+ * The handler runs once per spawn. If the host kills + respawns the
19
+ * JSContext (crash recovery, dev reload), the polyfill + bundle are
20
+ * re-evaluated and the handler fires again with a fresh session.
21
+ */
22
+
23
+ import {MiniappSession, type MiniappSessionOptions} from "../session"
24
+
25
+ export type TypedMiniappSession<TChannels extends object> = MiniappSession<TChannels>
26
+
27
+ export type MiniappInitHandler<TChannels extends object = Record<string, unknown>> = (
28
+ session: TypedMiniappSession<TChannels>,
29
+ ) => void | Promise<void>
30
+
31
+ interface InitGlobals {
32
+ __initCallback?: (sessionId: string) => void
33
+ /**
34
+ * Polyfill-injected host bridge for surfacing structured errors to the
35
+ * host's JSRouter (which feeds them into JSCrashController).
36
+ * Optional because tests / pure-Node environments don't have it.
37
+ */
38
+ __hostError?: (payloadJson: string) => void
39
+ }
40
+
41
+ /**
42
+ * Register the miniapp's startup handler. Call once at the top level of
43
+ * `src/background/index.ts`. Top-level side effects are fine, but the
44
+ * vast majority of setup should live inside the handler so it can run
45
+ * with a connected session.
46
+ *
47
+ * @example
48
+ * registerMiniapp((session) => {
49
+ * session.transcription.on((tx) => {
50
+ * session.display.render([{type: "text", id: "tx", box, text: tx.text}])
51
+ * })
52
+ * })
53
+ */
54
+ export function registerMiniapp<TChannels extends object = Record<string, unknown>>(
55
+ handler: MiniappInitHandler<TChannels>,
56
+ options: MiniappSessionOptions = {},
57
+ ): void {
58
+ const g = globalThis as unknown as InitGlobals
59
+ g.__initCallback = (_sessionId: string) => {
60
+ const session = new MiniappSession<TChannels>(options)
61
+ // Fire the user handler first so any session.* subscriptions get
62
+ // registered before the CONNECT_ACK fan-out lands.
63
+ try {
64
+ const result = handler(session)
65
+ if (result && typeof (result as Promise<void>).then === "function") {
66
+ ;(result as Promise<void>).catch((err: unknown) => {
67
+ console.error("[glassly-miniapp] registerMiniapp handler rejected:", err)
68
+ })
69
+ }
70
+ } catch (err) {
71
+ console.error("[glassly-miniapp] registerMiniapp handler threw:", err)
72
+ }
73
+ session.connect().catch((err: unknown) => {
74
+ console.error("[glassly-miniapp] session.connect() rejected:", err)
75
+ // Surface to the host's crash controller as a structured uncaught
76
+ // error so the existing backoff + crashloop machinery handles it.
77
+ // Repeated connect failures eventually flip the miniapp to
78
+ // CRASHLOOP_DISABLED, which the host turns into a user-facing
79
+ // alert + automatic incident report.
80
+ try {
81
+ const message = err instanceof Error ? err.message : String(err)
82
+ const stack = err instanceof Error && err.stack ? err.stack : ""
83
+ g.__hostError?.(JSON.stringify({message: `session.connect() failed: ${message}`, stack}))
84
+ } catch {
85
+ /* host bridge missing in tests — ignore */
86
+ }
87
+ })
88
+ }
89
+ }
@@ -0,0 +1,59 @@
1
+ /**
2
+ * @fileoverview SDK-side dev-reload listener — auto-installed when the host
3
+ * indicates we're running in a dev miniapp.
4
+ *
5
+ * Companion to the phone-side console-tap shim (which is injected by the
6
+ * Glassly app, not by the SDK). The SDK installs this listener on import so
7
+ * authors get live reload without any opt-in code.
8
+ *
9
+ * Mechanism:
10
+ * - Phone-side `DevServerBridge` receives `{type: "reload"}` from the dev
11
+ * server's WebSocket.
12
+ * - Phone-side `MiniappHost` then injects a `MessageEvent` into the WebView
13
+ * with payload `{type: "miniapp_dev_reload"}`.
14
+ * - This listener catches that MessageEvent and calls `location.reload()`.
15
+ *
16
+ * Gated on `window.Glassly.miniappDeveloperMode === true` so production
17
+ * miniapps never set up the listener. In production WebViews the host won't
18
+ * inject the message anyway, but belt-and-suspenders.
19
+ */
20
+
21
+ const RELOAD_MESSAGE_TYPE = "miniapp_dev_reload"
22
+
23
+ export function installDevReloadListenerIfDevMode(): void {
24
+ if (typeof window === "undefined") return
25
+ const glassly = (window as {Glassly?: {miniappDeveloperMode?: boolean}}).Glassly
26
+ if (!glassly?.miniappDeveloperMode) return
27
+
28
+ // Avoid double-install if the SDK is hot-reloaded mid-session.
29
+ const flagKey = "__devReloadInstalled"
30
+
31
+ if ((window as any)[flagKey]) return
32
+ ;(window as any)[flagKey] = true
33
+
34
+ const handler = (ev: MessageEvent): void => {
35
+ const data = typeof ev.data === "string" ? ev.data : null
36
+ if (!data) return
37
+ let parsed: unknown
38
+ try {
39
+ parsed = JSON.parse(data)
40
+ } catch {
41
+ return
42
+ }
43
+ const env = parsed as {payload?: {type?: string}}
44
+ const type = env?.payload?.type
45
+ if (type !== RELOAD_MESSAGE_TYPE) return
46
+
47
+ console.log("[glassly-miniapp] dev reload signal received — reloading")
48
+ try {
49
+ location.reload()
50
+ } catch {
51
+ // Some embedded contexts forbid reload; ignore.
52
+ }
53
+ }
54
+
55
+ window.addEventListener("message", handler)
56
+ if (typeof document !== "undefined") {
57
+ document.addEventListener("message", handler as unknown as EventListener)
58
+ }
59
+ }
@@ -0,0 +1,54 @@
1
+ /**
2
+ * @fileoverview Bridge envelope format.
3
+ *
4
+ * Every message between @glassly/miniapp and LocalMiniappRuntime is wrapped in
5
+ * this envelope for request/response correlation.
6
+ *
7
+ * { payload: {...}, requestId?: string }
8
+ */
9
+
10
+ export interface MiniappEnvelope<P = unknown> {
11
+ payload: P
12
+ /** Correlates request/response pairs. Set by the sender when it wants a reply. */
13
+ requestId?: string
14
+ }
15
+
16
+ /** Serialize an envelope for postMessage / WebSocket transport. */
17
+ export function serializeEnvelope(envelope: MiniappEnvelope): string {
18
+ return JSON.stringify(envelope)
19
+ }
20
+
21
+ /**
22
+ * Parse a serialized envelope. Returns null for any malformed input — never throws.
23
+ * Transports should pass raw strings in and silently drop nulls.
24
+ */
25
+ export function parseEnvelope(raw: unknown): MiniappEnvelope | null {
26
+ if (typeof raw !== "string") return null
27
+
28
+ let parsed: unknown
29
+ try {
30
+ parsed = JSON.parse(raw)
31
+ } catch {
32
+ return null
33
+ }
34
+
35
+ if (typeof parsed !== "object" || parsed === null) return null
36
+ const obj = parsed as Record<string, unknown>
37
+
38
+ if (typeof obj.payload !== "object" || obj.payload === null) return null
39
+ if (obj.requestId !== undefined && typeof obj.requestId !== "string") return null
40
+
41
+ return {
42
+ payload: obj.payload as unknown,
43
+ requestId: obj.requestId as string | undefined,
44
+ }
45
+ }
46
+
47
+ /** Generate a short random requestId. Browser-native (crypto.randomUUID). */
48
+ export function makeRequestId(): string {
49
+ if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
50
+ return crypto.randomUUID()
51
+ }
52
+ // Fallback for older engines: timestamp + random suffix. Not cryptographically secure.
53
+ return `req_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 10)}`
54
+ }
package/src/globals.ts ADDED
@@ -0,0 +1,62 @@
1
+ /**
2
+ * @fileoverview Shape of window.Glassly, injected by the host Glassly app
3
+ * before the miniapp's content loads. Miniapp authors generally won't read
4
+ * this directly — use the typed React hooks (useSafeArea, etc.) instead.
5
+ */
6
+
7
+ export interface MiniappSafeAreaInsets {
8
+ top: number
9
+ bottom: number
10
+ left: number
11
+ right: number
12
+ }
13
+
14
+ export interface MiniappCapsuleMenuRect {
15
+ top: number
16
+ right: number
17
+ bottom: number
18
+ left: number
19
+ width: number
20
+ height: number
21
+ }
22
+
23
+ export type MiniappColorScheme = "light" | "dark"
24
+
25
+ export interface GlasslyGlobals {
26
+ /** Package id the host assigned to this miniapp (e.g. "com.glassly.example"). */
27
+ packageName?: string
28
+ /** "ios" | "android" | other. */
29
+ platform?: string
30
+ /** Capabilities the host exposes to this miniapp (e.g. ["share", "open_url"]). */
31
+ capabilities?: string[]
32
+ /** True when this miniapp is running locally on-device (vs. hosted in the cloud). */
33
+ miniappLocal?: boolean
34
+ /** True when the miniapp is running via the dev workflow (QR sideload). */
35
+ miniappDeveloperMode?: boolean
36
+ /** Safe-area insets around the WebView content. Miniapps should pad accordingly. */
37
+ safeAreaInsets?: MiniappSafeAreaInsets
38
+ /**
39
+ * Bounding rect (in CSS pixels) of the floating capsule menu the host draws
40
+ * over the WebView. The menu lives in the top-right and miniapps should
41
+ * avoid placing interactive elements beneath it.
42
+ */
43
+ capsuleMenu?: MiniappCapsuleMenuRect
44
+ /**
45
+ * The host's current color scheme. Miniapps can follow this to match the
46
+ * phone's appearance. Updates at runtime arrive via the session's
47
+ * `colorScheme` event — see `useColorScheme()` in @glassly/miniapp/react.
48
+ */
49
+ colorScheme?: MiniappColorScheme
50
+ }
51
+
52
+ declare global {
53
+ interface Window {
54
+ Glassly?: GlasslyGlobals
55
+ }
56
+ }
57
+
58
+ /** Reads window.Glassly safely — returns an empty object if not set. */
59
+ export function getGlasslyGlobals(): GlasslyGlobals {
60
+ if (typeof window === "undefined") return {}
61
+ return window.Glassly ?? {}
62
+ }
@@ -0,0 +1,25 @@
1
+ /** Hardware components that a miniapp can declare in its manifest. */
2
+ export enum HardwareType {
3
+ CAMERA = "CAMERA",
4
+ DISPLAY = "DISPLAY",
5
+ MICROPHONE = "MICROPHONE",
6
+ SPEAKER = "SPEAKER",
7
+ IMU = "IMU",
8
+ BUTTON = "BUTTON",
9
+ LIGHT = "LIGHT",
10
+ WIFI = "WIFI",
11
+ EXIST = "EXIST",
12
+ }
13
+
14
+ /** Whether a missing component prevents the miniapp from running. */
15
+ export enum HardwareRequirementLevel {
16
+ REQUIRED = "REQUIRED",
17
+ OPTIONAL = "OPTIONAL",
18
+ }
19
+
20
+ /** One hardware requirement from a miniapp manifest. */
21
+ export interface HardwareRequirement {
22
+ type: HardwareType
23
+ level: HardwareRequirementLevel
24
+ description?: string
25
+ }
package/src/index.ts ADDED
@@ -0,0 +1,216 @@
1
+ /**
2
+ * @glassly/miniapp — SDK for building Glassly local miniapps.
3
+ *
4
+ * Public entry point. Consumers do:
5
+ *
6
+ * import {MiniappSession} from "@glassly/miniapp" // background JSContext
7
+ * import {useColorScheme} from "@glassly/miniapp/react" // UI WebView hooks
8
+ * import {MiniappRequestType} from "@glassly/miniapp/protocol"
9
+ */
10
+
11
+ import {installDevReloadListenerIfDevMode} from "./dev-reload"
12
+
13
+ // Auto-install the dev-reload listener on module import so authors get live
14
+ // reload for free in dev builds. No-op in production (gated on
15
+ // window.Glassly.miniappDeveloperMode).
16
+ installDevReloadListenerIfDevMode()
17
+
18
+ export {MiniappSession, NotConnectedError} from "./session"
19
+ export type {
20
+ AuthUpdatePayload,
21
+ ConnectAckPayload,
22
+ DisplayCapabilities,
23
+ GlassesCapabilities,
24
+ MiniappAuthState,
25
+ MiniappRequestError,
26
+ MiniappSessionOptions,
27
+ MiniappVisibility,
28
+ } from "./session"
29
+ export type {AuthFetchOptions, AuthModule} from "./modules/auth"
30
+
31
+ export {makeRequestId, parseEnvelope, serializeEnvelope} from "./envelope"
32
+ export type {MiniappEnvelope} from "./envelope"
33
+
34
+ export {getGlasslyGlobals} from "./globals"
35
+ export type {GlasslyGlobals, MiniappCapsuleMenuRect, MiniappColorScheme, MiniappSafeAreaInsets} from "./globals"
36
+
37
+ export {MiniappErrorCode, MiniappRequestType, MiniappResponseType, MiniappStreamType} from "./protocol"
38
+ export {CLOUD_STATUS_STREAM} from "./modules/cloud"
39
+
40
+ // Language registry (issue 021): canonical language types + the validation
41
+ // error the typed transcription/translation surfaces throw.
42
+ export {
43
+ MiniappValidationError,
44
+ SUPPORTED_LANGUAGE_HINTS,
45
+ SUPPORTED_TRANSCRIPTION_LANGUAGES,
46
+ isTranscriptionLanguage,
47
+ } from "./modules/languages"
48
+ export type {LanguageHint, TranscriptionLanguage} from "./modules/languages"
49
+ export type {CloudClientAudioTransport, CloudClientConnectionStatus, CloudClientStatus} from "./modules/cloud"
50
+
51
+ // Hardware requirement types — canonical defs live in ./hardware; miniapp
52
+ // authors type their miniapp.json manifest with these, and @glassly/engine
53
+ // re-exports them. Keep explicit exports (enums as value, interfaces as
54
+ // type) for Bun compat.
55
+ export {HardwareType, HardwareRequirementLevel} from "./hardware"
56
+ export type {HardwareRequirement} from "./hardware"
57
+
58
+ // Transports — exported for advanced uses (forced transport injection, tests)
59
+ export {createTransport} from "./transport/auto"
60
+ export type {CreateTransportOptions} from "./transport/auto"
61
+ export {PostMessageTransport} from "./transport/postmessage"
62
+ export {LocalSocketTransport} from "./transport/local-socket"
63
+ export type {LocalSocketTransportOptions} from "./transport/local-socket"
64
+ export {MockTransport, isMockExplicitlyRequested} from "./transport/mock"
65
+ export type {MockTransportOptions} from "./transport/mock"
66
+ export type {Transport, TransportDisconnectHandler, TransportMessageHandler} from "./transport/types"
67
+
68
+ // Module types — useful for typing handlers in consumer code
69
+ export type {
70
+ DisplayBreakMode,
71
+ NativeNavInfo,
72
+ NativeNavResult,
73
+ RenderBox,
74
+ RenderElement,
75
+ RenderOptions,
76
+ RenderRectStyle,
77
+ RenderResult,
78
+ RenderTextStyle,
79
+ ViewType,
80
+ } from "./modules/display"
81
+ export type {
82
+ AccelData,
83
+ AudioChunkData,
84
+ BatteryData,
85
+ ButtonPressData,
86
+ ConnectionData,
87
+ HeadingData,
88
+ HeadPositionData,
89
+ LocationData,
90
+ NotificationDismissedData,
91
+ PhoneNotificationData,
92
+ TouchData,
93
+ TranscriptionData,
94
+ TranslationData,
95
+ UnsubscribeFn,
96
+ VadData,
97
+ WifiData,
98
+ } from "./modules/events"
99
+ export type {CalendarEvent, CalendarListOptions, CalendarListResult} from "./modules/phone"
100
+ export type {
101
+ PlayAudioOptions,
102
+ SpeakOptions,
103
+ SpeakResult,
104
+ SpeakerState,
105
+ SpeakerStateEvent,
106
+ SpeakerStreamOptions,
107
+ SpeakerStreamSampleRate,
108
+ SpeakerStreamWriteResult,
109
+ } from "./modules/speaker"
110
+ export {SpeakerStreamWriter, SPEAKER_STREAM_MAX_BUFFERED_MS, SPEAKER_WRITE_CHUNK_BYTES} from "./modules/speaker"
111
+ export type {
112
+ CameraFovPreset,
113
+ CameraFovRequest,
114
+ CameraFovResult,
115
+ CameraRoiPosition,
116
+ PhotoTaken,
117
+ SetCameraFovOptions,
118
+ StartVideoRecordingOptions,
119
+ StopVideoRecordingOptions,
120
+ TakePhotoOptions,
121
+ VideoRecordingStarted,
122
+ } from "./modules/camera"
123
+ export type {DashboardMode, ShowNativeDashboardResult} from "./modules/dashboard"
124
+ export type {CloudModule} from "./modules/cloud"
125
+ export type {LedColor, LedControlOptions} from "./modules/led"
126
+ export type {
127
+ RestreamDestination,
128
+ StartStreamOptions,
129
+ StreamAudioConfig,
130
+ StreamResolvedConfig,
131
+ StreamResult,
132
+ StreamStatus,
133
+ StreamVideoConfig,
134
+ } from "./modules/stream"
135
+ export type {
136
+ ShareOptions,
137
+ ShareResult,
138
+ DownloadOptions,
139
+ DownloadResult,
140
+ ScanQrOptions,
141
+ ScanQrResult,
142
+ } from "./modules/system"
143
+ export type {MiniappInfo, MiniappActionInfo, MiniappCompatibility, ListMiniappsOptions} from "./modules/miniapps"
144
+ export type {ActionContext, ActionDescriptor, ActionHandler, InvokeOptions} from "./modules/actions"
145
+
146
+ // Domain module types — exported so consumers can type module references
147
+ // (rare; most authors interact via session.<module>.<method> directly).
148
+ export type {DisplayManager} from "./modules/display"
149
+ export type {MiniappsModule} from "./modules/miniapps"
150
+ export type {ActionsModule} from "./modules/actions"
151
+ export type {GlassesModule} from "./modules/glasses"
152
+ export type {HeadingModule} from "./modules/heading"
153
+ export type {
154
+ AiModule,
155
+ AiProvider,
156
+ AiTier,
157
+ AiTool,
158
+ AiToolCall,
159
+ AiToolResult,
160
+ AiMessage,
161
+ AiCompleteRequest,
162
+ AiCompleteResult,
163
+ AiStopReason,
164
+ AiUsage,
165
+ } from "./modules/ai"
166
+ export type {ImuModule} from "./modules/imu"
167
+ export type {InputModule} from "./modules/input"
168
+ export type {KeysModule, ApiKeyProvider} from "./modules/keys"
169
+ export type {LocationModule} from "./modules/location"
170
+ export type {
171
+ MemoryModule,
172
+ MemoryEntry,
173
+ MemoryEntryKind,
174
+ MemoryNoteSource,
175
+ MemoryQuery,
176
+ MemorySearchResult,
177
+ MemorySession,
178
+ MemorySummary,
179
+ } from "./modules/memory"
180
+ export type {SpeakersModule} from "./modules/speakers"
181
+ export type {MicModule} from "./modules/mic"
182
+ export type {
183
+ ComputedRoute,
184
+ ComputedRouteStep,
185
+ ComputeRouteOptions,
186
+ ComputeRouteResult,
187
+ LatLng,
188
+ NavArrived,
189
+ NavCancelled,
190
+ NavError,
191
+ NavigationModule,
192
+ NavManeuver,
193
+ NavOffRoute,
194
+ NavPermissionResult,
195
+ NavPlaceDetails,
196
+ NavPlaceSuggestion,
197
+ NavRerouting,
198
+ NavRoute,
199
+ NavState,
200
+ NavStep,
201
+ NavUpdate,
202
+ Pivot,
203
+ PivotEvent,
204
+ PivotOptions,
205
+ RouteAvoidances,
206
+ StartNavigationOptions,
207
+ TravelMode,
208
+ } from "./modules/navigation"
209
+ export type {PermissionsModule, PermissionErrorEvent} from "./modules/permissions"
210
+ export type {PhoneModule, PhoneNotificationsModule, PhoneCalendarModule} from "./modules/phone"
211
+ export type {TranscriptionModule, TranscriptionConfig, TranscriptionOptions} from "./modules/transcription"
212
+ export type {TranslationModule} from "./modules/translation"
213
+ export type {SpeakerModule} from "./modules/speaker"
214
+
215
+ // Permission types
216
+ export type {PermissionType, PermissionRecord} from "./session"