@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,39 @@
1
+ /**
2
+ * @fileoverview LocationModule — phone location events.
3
+ *
4
+ * Exposes both a continuous `onUpdate` subscription and a one-shot
5
+ * `getOnce()` poll over `MiniappRequestType.LOCATION_POLL`.
6
+ *
7
+ * LOCATION permission must be declared in miniapp.json for either path to
8
+ * succeed; the phone runtime rejects with PERMISSION_NOT_DECLARED
9
+ * otherwise.
10
+ */
11
+
12
+ import {MiniappRequestType, MiniappStreamType} from "../protocol"
13
+ import {MiniappSession} from "../session"
14
+ import type {LocationData, UnsubscribeFn} from "./events"
15
+
16
+ export class LocationModule {
17
+ constructor(private readonly session: MiniappSession) {}
18
+
19
+ /** True iff `LOCATION` is declared in the miniapp's manifest. */
20
+ get hasPermission(): boolean {
21
+ return this.session._hasManifestPermission("LOCATION")
22
+ }
23
+
24
+ /** Subscribe to continuous location updates. */
25
+ onUpdate(handler: (data: LocationData) => void): UnsubscribeFn {
26
+ return this.session._subscribe(MiniappStreamType.LOCATION_UPDATE, handler as (data: unknown) => void)
27
+ }
28
+
29
+ /**
30
+ * Request a single location fix. Resolves with the next available
31
+ * reading from the phone. Useful at app load to seed UI before a
32
+ * continuous stream of updates begins.
33
+ */
34
+ getOnce(): Promise<LocationData> {
35
+ return this.session.sendRequest<LocationData>({
36
+ type: MiniappRequestType.LOCATION_POLL,
37
+ })
38
+ }
39
+ }
@@ -0,0 +1,224 @@
1
+ /**
2
+ * @fileoverview MemoryModule — the user's shared, phone-local memory timeline.
3
+ *
4
+ * One unified per-hour stream of what happened around the user — spoken
5
+ * transcript lines AND notes (manual, voice, auto) — plus the hourly summary
6
+ * that heads each session. The store lives on the phone (host-level,
7
+ * user-scoped), NOT in the per-miniapp storage namespace: every miniapp that
8
+ * declares the MEMORY manifest permission reads and writes the same timeline,
9
+ * and the user manages it in Settings > Memory.
10
+ *
11
+ * A "session" is one clock hour that has entries, derived from entry
12
+ * timestamps at read time — there is no stored session id.
13
+ *
14
+ * All calls require the MEMORY manifest permission; without it the host
15
+ * rejects with PERMISSION_NOT_DECLARED. Nothing here leaves the phone.
16
+ */
17
+
18
+ import {MiniappRequestType} from "../protocol"
19
+ import {MiniappSession} from "../session"
20
+
21
+ export type MemoryEntryKind = "line" | "note"
22
+ /** How a note entry originated (only meaningful when kind === "note"). */
23
+ export type MemoryNoteSource = "voice" | "ui" | "auto"
24
+
25
+ export interface MemoryEntry {
26
+ id: string
27
+ kind: MemoryEntryKind
28
+ text: string
29
+ /** Epoch ms the entry happened. */
30
+ at: number
31
+ speakerId: string | null
32
+ /** Enrolled-speaker display name resolved by on-device speaker ID, when known. */
33
+ resolvedSpeakerName?: string | null
34
+ language: string | null
35
+ /** Present for note entries. */
36
+ source?: MemoryNoteSource
37
+ }
38
+
39
+ export interface MemorySummary {
40
+ /** Epoch ms of the hour bucket start. */
41
+ hourStart: number
42
+ text: string
43
+ createdAt: number
44
+ }
45
+
46
+ /** One derived session: a clock hour with its entries and summary. */
47
+ export interface MemorySession {
48
+ hourStart: number
49
+ entries: MemoryEntry[]
50
+ summary: string | null
51
+ lineCount: number
52
+ noteCount: number
53
+ }
54
+
55
+ export interface MemoryQuery {
56
+ /** Epoch ms lower bound (inclusive). Omit for "from the beginning". */
57
+ sinceMs?: number
58
+ /** Epoch ms upper bound (inclusive). Omit for "until now". */
59
+ untilMs?: number
60
+ /** Case-insensitive EXACT substring filter (codes, URLs, exact phrases). */
61
+ contains?: string
62
+ /**
63
+ * Fuzzy any-of terms: an entry matches when ANY term matches, and a
64
+ * multi-word term requires all of its words. Matching tolerates the small
65
+ * misspellings speech-to-text produces for names ("Korwin" matches
66
+ * "Corwin"). Host caps at 8 terms. Combined with `contains` as AND.
67
+ * Ignored by hosts that predate fuzzy search.
68
+ */
69
+ terms?: string[]
70
+ /** Max entries returned (host caps at 200; default 60). Newest kept. */
71
+ limit?: number
72
+ }
73
+
74
+ export interface MemorySearchResult {
75
+ /** Matches in chronological order (newest last). */
76
+ entries: MemoryEntry[]
77
+ /**
78
+ * Entries inside the TIME window before keyword filtering — distinguishes
79
+ * "keyword matched nothing" from "window empty". Undefined on hosts that
80
+ * predate fuzzy search.
81
+ */
82
+ windowCount?: number
83
+ }
84
+
85
+ export class MemoryModule {
86
+ constructor(private readonly session: MiniappSession) {}
87
+
88
+ /** True iff this miniapp's manifest declares the MEMORY permission. */
89
+ get hasPermission(): boolean {
90
+ return this.session._hasManifestPermission("MEMORY")
91
+ }
92
+
93
+ /** Append a spoken transcript line to the timeline. */
94
+ async appendLine(input: {
95
+ text: string
96
+ speakerId: string | null
97
+ language: string | null
98
+ at: number
99
+ }): Promise<void> {
100
+ await this.session.sendRequest<void>({
101
+ type: MiniappRequestType.MEMORY_APPEND_LINE,
102
+ ...input,
103
+ })
104
+ }
105
+
106
+ /**
107
+ * Add a note. `at` targets the hour it belongs to — omit for "now" (the
108
+ * current session), or pass a timestamp inside a past hour to append to
109
+ * that session. Notes dedupe on normalized text within the same hour;
110
+ * resolves null when the note was a duplicate (or empty).
111
+ */
112
+ async addNote(text: string, source: MemoryNoteSource = "ui", at?: number): Promise<MemoryEntry | null> {
113
+ const result = await this.session.sendRequest<{entry: MemoryEntry | null}>({
114
+ type: MiniappRequestType.MEMORY_ADD_NOTE,
115
+ text,
116
+ source,
117
+ at,
118
+ })
119
+ return result?.entry ?? null
120
+ }
121
+
122
+ /** Delete one entry (line or note) by id. Resolves false when unknown. */
123
+ async removeEntry(id: string): Promise<boolean> {
124
+ const result = await this.session.sendRequest<{removed: boolean}>({
125
+ type: MiniappRequestType.MEMORY_REMOVE_ENTRY,
126
+ id,
127
+ })
128
+ return !!result?.removed
129
+ }
130
+
131
+ /** Delete every entry (and summary) in an hour, or a whole day of hours. */
132
+ async removeScope(scope: "session" | "day", at: number): Promise<void> {
133
+ await this.session.sendRequest<void>({
134
+ type: MiniappRequestType.MEMORY_REMOVE_SCOPE,
135
+ scope,
136
+ at,
137
+ })
138
+ }
139
+
140
+ /** All sessions (hours with entries), newest hour first. */
141
+ async sessions(): Promise<MemorySession[]> {
142
+ const result = await this.session.sendRequest<{sessions: MemorySession[]}>({
143
+ type: MiniappRequestType.MEMORY_SESSION_LIST,
144
+ })
145
+ return result?.sessions ?? []
146
+ }
147
+
148
+ /**
149
+ * Query the full timeline by absolute-time window and keyword — the
150
+ * on-device executor shape for LLM history-search tools. Newest last, so
151
+ * slicing keeps the most recent matches when the limit bites.
152
+ */
153
+ async query(q: MemoryQuery = {}): Promise<MemoryEntry[]> {
154
+ return (await this.search(q)).entries
155
+ }
156
+
157
+ /**
158
+ * query() plus search diagnostics ({@link MemorySearchResult.windowCount}).
159
+ * Same wire request; prefer this from LLM history-search tools so an empty
160
+ * result can explain WHY it was empty instead of triggering a blind retry.
161
+ */
162
+ async search(q: MemoryQuery = {}): Promise<MemorySearchResult> {
163
+ const result = await this.session.sendRequest<{entries: MemoryEntry[]; windowCount?: number}>({
164
+ type: MiniappRequestType.MEMORY_QUERY,
165
+ ...q,
166
+ })
167
+ return {
168
+ entries: result?.entries ?? [],
169
+ ...(typeof result?.windowCount === "number" ? {windowCount: result.windowCount} : {}),
170
+ }
171
+ }
172
+
173
+ /** Entries in [sinceMs, untilMs), newest last. Uncapped (unlike query). */
174
+ async window(sinceMs: number, untilMs?: number): Promise<MemoryEntry[]> {
175
+ const result = await this.session.sendRequest<{entries: MemoryEntry[]}>({
176
+ type: MiniappRequestType.MEMORY_WINDOW,
177
+ sinceMs,
178
+ untilMs,
179
+ })
180
+ return result?.entries ?? []
181
+ }
182
+
183
+ /** Plain-text export of a scope, for the OS share sheet. */
184
+ async exportText(scope: "session" | "day" | "all", at?: number): Promise<string> {
185
+ const result = await this.session.sendRequest<{text: string}>({
186
+ type: MiniappRequestType.MEMORY_EXPORT_TEXT,
187
+ scope,
188
+ at,
189
+ })
190
+ return result?.text ?? ""
191
+ }
192
+
193
+ /** Upsert the summary heading an hour (keyed by hourStart). */
194
+ async addSummary(summary: MemorySummary): Promise<void> {
195
+ await this.session.sendRequest<void>({
196
+ type: MiniappRequestType.MEMORY_SUMMARY_ADD,
197
+ ...summary,
198
+ })
199
+ }
200
+
201
+ /** All hourly summaries, newest hour first. */
202
+ async summaries(): Promise<MemorySummary[]> {
203
+ const result = await this.session.sendRequest<{summaries: MemorySummary[]}>({
204
+ type: MiniappRequestType.MEMORY_SUMMARY_LIST,
205
+ })
206
+ return result?.summaries ?? []
207
+ }
208
+
209
+ /** Most recent COMPLETED hour with lines but no summary, or null. */
210
+ async pendingSummaryHour(nowMs?: number): Promise<number | null> {
211
+ const result = await this.session.sendRequest<{hourStart: number | null}>({
212
+ type: MiniappRequestType.MEMORY_PENDING_SUMMARY_HOUR,
213
+ nowMs,
214
+ })
215
+ return result?.hourStart ?? null
216
+ }
217
+
218
+ /** Drop the entire timeline: every entry and every summary. */
219
+ async clear(): Promise<void> {
220
+ await this.session.sendRequest<void>({
221
+ type: MiniappRequestType.MEMORY_CLEAR,
222
+ })
223
+ }
224
+ }
@@ -0,0 +1,103 @@
1
+ /**
2
+ * @fileoverview MicModule — low-level audio input subscriptions.
3
+ *
4
+ * Mirrors cloud SDK v3's MicManager naming. Houses raw audio chunks + VAD;
5
+ * transcription and translation hoisted to top-level (`session.transcription`
6
+ * / `session.translation`) in the v3-alignment round so authors don't have to
7
+ * mentally model "transcription is a microphone thing" — it's just a
8
+ * top-level domain. This module was called `MicrophoneModule` /
9
+ * `session.microphone` before that round.
10
+ *
11
+ * Audio *output* (TTS, file playback) lives on `session.speaker`.
12
+ *
13
+ * MICROPHONE permission must be declared in miniapp.json for any of these
14
+ * subscriptions to succeed; the phone runtime rejects with
15
+ * PERMISSION_NOT_DECLARED otherwise.
16
+ */
17
+
18
+ import {MiniappRequestType, MiniappStreamType} from "../protocol"
19
+ import {MiniappSession} from "../session"
20
+ import type {AudioChunkData, UnsubscribeFn, VadData} from "./events"
21
+
22
+ export class MicModule {
23
+ /** All active unsubscribe functions for stop() to tear down at once. */
24
+ private readonly unsubs = new Set<UnsubscribeFn>()
25
+
26
+ constructor(private readonly session: MiniappSession) {}
27
+
28
+ /**
29
+ * Subscribe to voice activity detection (VAD) events. `data.status` is
30
+ * `true` while the user is speaking, `false` when silent.
31
+ */
32
+ onVoiceActivity(handler: (data: VadData) => void): UnsubscribeFn {
33
+ return this.track(this.session._subscribe(MiniappStreamType.VAD, handler as (data: unknown) => void))
34
+ }
35
+
36
+ /**
37
+ * Subscribe to raw audio chunks. Format depends on the phone's mic mode
38
+ * (PCM or LC3, base64-encoded).
39
+ */
40
+ onAudioChunk(handler: (data: AudioChunkData) => void): UnsubscribeFn {
41
+ return this.track(this.session._subscribe(MiniappStreamType.AUDIO_CHUNK, handler as (data: unknown) => void))
42
+ }
43
+
44
+ /**
45
+ * Temporarily override glasses-side voice activity detection (GX8002) for
46
+ * this miniapp's lifetime. When disabled, mic gating falls back to the
47
+ * loudness gate only (if it is enabled). The Glassly App's configured value
48
+ * is restored when this miniapp disconnects.
49
+ *
50
+ * Requires `MICROPHONE` in the miniapp manifest.
51
+ */
52
+ setVoiceActivityDetectionEnabled(enabled: boolean): Promise<void> {
53
+ return this.session.sendRequest<void>({
54
+ type: MiniappRequestType.MIC_SET_VAD_ENABLED,
55
+ enabled,
56
+ })
57
+ }
58
+
59
+ /**
60
+ * Temporarily override the center-mic loudness gate ("Barrier") for this
61
+ * miniapp's lifetime. It blocks quiet/self-talk audio independent of VAD.
62
+ * The Glassly App's configured value is restored when this miniapp disconnects.
63
+ *
64
+ * Requires `MICROPHONE` in the miniapp manifest.
65
+ */
66
+ setLoudnessGateEnabled(enabled: boolean): Promise<void> {
67
+ return this.session.sendRequest<void>({
68
+ type: MiniappRequestType.MIC_SET_LOUDNESS_GATE_ENABLED,
69
+ enabled,
70
+ })
71
+ }
72
+
73
+ /**
74
+ * Tear down every subscription this module owns. Useful when a component
75
+ * is unmounting and wants to free everything at once without tracking
76
+ * individual unsubscribe functions.
77
+ */
78
+ stop(): void {
79
+ for (const u of this.unsubs) {
80
+ try {
81
+ u()
82
+ } catch {
83
+ /* ignore */
84
+ }
85
+ }
86
+ this.unsubs.clear()
87
+ }
88
+
89
+ /** True iff `MICROPHONE` is declared in the miniapp's manifest. */
90
+ get hasPermission(): boolean {
91
+ return this.session._hasManifestPermission("MICROPHONE")
92
+ }
93
+
94
+ // ------------------------------------------------------------------------
95
+
96
+ private track(unsub: UnsubscribeFn): UnsubscribeFn {
97
+ this.unsubs.add(unsub)
98
+ return () => {
99
+ this.unsubs.delete(unsub)
100
+ unsub()
101
+ }
102
+ }
103
+ }
@@ -0,0 +1,103 @@
1
+ /**
2
+ * @fileoverview MiniappsModule — `session.miniapps`.
3
+ *
4
+ * Discover and control the lifecycle of OTHER miniapps: list, start, stop.
5
+ * SYSTEM-only — every call rejects with NOT_PERMITTED unless the caller is a
6
+ * system app (Glassly AI is the first consumer). The action *capability* layer
7
+ * (invoke / handle) lives on `session.actions`, not here — these three are
8
+ * operations on the app as a whole, not on a declared action.
9
+ */
10
+
11
+ import {MiniappRequestType} from "../protocol"
12
+ import {MiniappSession} from "../session"
13
+
14
+ /** A declared action surfaced by {@link MiniappsModule.list}. */
15
+ export interface MiniappActionInfo {
16
+ id: string
17
+ description: string
18
+ /**
19
+ * JSON-Schema input descriptor (the MCP-compatible subset). Maps verbatim
20
+ * to an MCP tool `inputSchema`. Undefined for actions that take no params.
21
+ */
22
+ parameters?: Record<string, unknown>
23
+ /** JSON-Schema descriptor for the structured value returned by the action. */
24
+ outputSchema?: Record<string, unknown>
25
+ }
26
+
27
+ /**
28
+ * Hardware compatibility for a listed miniapp. Structurally mirrors the host's
29
+ * `CompatibilityResult` so the runtime can pass it straight through.
30
+ */
31
+ export interface MiniappCompatibility {
32
+ isCompatible: boolean
33
+ missingRequired: Array<{type: string; level?: string}>
34
+ missingOptional: Array<{type: string; level?: string}>
35
+ warnings: string[]
36
+ }
37
+
38
+ /** One installed miniapp, as surfaced to a system caller. */
39
+ export interface MiniappInfo {
40
+ packageName: string
41
+ name: string
42
+ description?: string
43
+ version: string
44
+ running: boolean
45
+ compatibility: MiniappCompatibility
46
+ /** Declared actions (empty if the miniapp declares none). */
47
+ actions: MiniappActionInfo[]
48
+ }
49
+
50
+ export interface ListMiniappsOptions {
51
+ /** Include incompatible miniapps too (default false — compatible-only). */
52
+ includeIncompatible?: boolean
53
+ }
54
+
55
+ export class MiniappsModule {
56
+ constructor(private readonly session: MiniappSession) {}
57
+
58
+ /**
59
+ * List installed miniapps. Compatible-only by default; pass
60
+ * `{includeIncompatible: true}` to include the rest (each carries a
61
+ * `compatibility` result with the missing hardware). SYSTEM-only.
62
+ */
63
+ async list(opts?: ListMiniappsOptions): Promise<MiniappInfo[]> {
64
+ const result = await this.session.sendRequest<MiniappInfo[]>({
65
+ type: MiniappRequestType.MINIAPPS_LIST,
66
+ includeIncompatible: opts?.includeIncompatible ?? false,
67
+ })
68
+ return result ?? []
69
+ }
70
+
71
+ /**
72
+ * Start another miniapp in the **background** — spawns its background JS
73
+ * context without changing the user's phone navigation or foregrounding
74
+ * anything. The app reports as running and can handle actions / drive the
75
+ * glasses immediately; its WebView only mounts if the user later opens it.
76
+ * SYSTEM-only.
77
+ */
78
+ async start(packageName: string): Promise<void> {
79
+ await this.session.sendRequest<void>({
80
+ type: MiniappRequestType.MINIAPPS_START,
81
+ packageName,
82
+ })
83
+ }
84
+
85
+ /** Stop another miniapp. SYSTEM-only. */
86
+ async stop(packageName: string): Promise<void> {
87
+ await this.session.sendRequest<void>({
88
+ type: MiniappRequestType.MINIAPPS_STOP,
89
+ packageName,
90
+ })
91
+ }
92
+
93
+ /**
94
+ * Stop THIS miniapp — the host tears the background context down shortly
95
+ * after. Not system-gated: an app may always stop itself. Fire-and-forget
96
+ * (no reply — the caller is going away); flush anything pending first, e.g.
97
+ * defer this with a short setTimeout from an action handler so the
98
+ * ACTION_RESULT reaches the caller before teardown.
99
+ */
100
+ stopSelf(): void {
101
+ this.session.sendOneShot({type: MiniappRequestType.MINIAPPS_STOP_SELF})
102
+ }
103
+ }