@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.
- package/README.md +275 -0
- package/dist/background/index.d.ts +64 -0
- package/dist/background/index.d.ts.map +1 -0
- package/dist/background/index.js +26 -0
- package/dist/background/index.js.map +1 -0
- package/dist/background/register.d.ts +39 -0
- package/dist/background/register.d.ts.map +1 -0
- package/dist/background/register.js +72 -0
- package/dist/background/register.js.map +1 -0
- package/dist/dev-reload.d.ts +21 -0
- package/dist/dev-reload.d.ts.map +1 -0
- package/dist/dev-reload.js +60 -0
- package/dist/dev-reload.js.map +1 -0
- package/dist/envelope.d.ts +23 -0
- package/dist/envelope.d.ts.map +1 -0
- package/dist/envelope.js +47 -0
- package/dist/envelope.js.map +1 -0
- package/dist/globals.d.ts +54 -0
- package/dist/globals.d.ts.map +1 -0
- package/dist/globals.js +12 -0
- package/dist/globals.js.map +1 -0
- package/dist/hardware.d.ts +24 -0
- package/dist/hardware.d.ts.map +1 -0
- package/dist/hardware.js +20 -0
- package/dist/hardware.js.map +1 -0
- package/dist/index.d.ts +65 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/modules/actions.d.ts +81 -0
- package/dist/modules/actions.d.ts.map +1 -0
- package/dist/modules/actions.js +137 -0
- package/dist/modules/actions.js.map +1 -0
- package/dist/modules/ai.d.ts +211 -0
- package/dist/modules/ai.d.ts.map +1 -0
- package/dist/modules/ai.js +117 -0
- package/dist/modules/ai.js.map +1 -0
- package/dist/modules/auth.d.ts +25 -0
- package/dist/modules/auth.d.ts.map +1 -0
- package/dist/modules/auth.js +52 -0
- package/dist/modules/auth.js.map +1 -0
- package/dist/modules/base64.d.ts +16 -0
- package/dist/modules/base64.d.ts.map +1 -0
- package/dist/modules/base64.js +92 -0
- package/dist/modules/base64.js.map +1 -0
- package/dist/modules/blob.d.ts +161 -0
- package/dist/modules/blob.d.ts.map +1 -0
- package/dist/modules/blob.js +277 -0
- package/dist/modules/blob.js.map +1 -0
- package/dist/modules/camera.d.ts +183 -0
- package/dist/modules/camera.d.ts.map +1 -0
- package/dist/modules/camera.js +119 -0
- package/dist/modules/camera.js.map +1 -0
- package/dist/modules/cloud.d.ts +34 -0
- package/dist/modules/cloud.d.ts.map +1 -0
- package/dist/modules/cloud.js +70 -0
- package/dist/modules/cloud.js.map +1 -0
- package/dist/modules/dashboard.d.ts +24 -0
- package/dist/modules/dashboard.d.ts.map +1 -0
- package/dist/modules/dashboard.js +39 -0
- package/dist/modules/dashboard.js.map +1 -0
- package/dist/modules/display.d.ts +174 -0
- package/dist/modules/display.d.ts.map +1 -0
- package/dist/modules/display.js +83 -0
- package/dist/modules/display.js.map +1 -0
- package/dist/modules/events.d.ts +178 -0
- package/dist/modules/events.d.ts.map +1 -0
- package/dist/modules/events.js +168 -0
- package/dist/modules/events.js.map +1 -0
- package/dist/modules/glasses.d.ts +36 -0
- package/dist/modules/glasses.d.ts.map +1 -0
- package/dist/modules/glasses.js +52 -0
- package/dist/modules/glasses.js.map +1 -0
- package/dist/modules/heading.d.ts +16 -0
- package/dist/modules/heading.d.ts.map +1 -0
- package/dist/modules/heading.js +20 -0
- package/dist/modules/heading.js.map +1 -0
- package/dist/modules/imu.d.ts +31 -0
- package/dist/modules/imu.d.ts.map +1 -0
- package/dist/modules/imu.js +40 -0
- package/dist/modules/imu.js.map +1 -0
- package/dist/modules/input.d.ts +50 -0
- package/dist/modules/input.d.ts.map +1 -0
- package/dist/modules/input.js +70 -0
- package/dist/modules/input.js.map +1 -0
- package/dist/modules/keys.d.ts +30 -0
- package/dist/modules/keys.d.ts.map +1 -0
- package/dist/modules/keys.js +37 -0
- package/dist/modules/keys.js.map +1 -0
- package/dist/modules/languages.d.ts +42 -0
- package/dist/modules/languages.d.ts.map +1 -0
- package/dist/modules/languages.js +57 -0
- package/dist/modules/languages.js.map +1 -0
- package/dist/modules/led.d.ts +35 -0
- package/dist/modules/led.d.ts.map +1 -0
- package/dist/modules/led.js +39 -0
- package/dist/modules/led.js.map +1 -0
- package/dist/modules/location.d.ts +27 -0
- package/dist/modules/location.d.ts.map +1 -0
- package/dist/modules/location.js +35 -0
- package/dist/modules/location.js.map +1 -0
- package/dist/modules/memory.d.ts +126 -0
- package/dist/modules/memory.d.ts.map +1 -0
- package/dist/modules/memory.js +141 -0
- package/dist/modules/memory.js.map +1 -0
- package/dist/modules/mic.d.ts +61 -0
- package/dist/modules/mic.d.ts.map +1 -0
- package/dist/modules/mic.js +94 -0
- package/dist/modules/mic.js.map +1 -0
- package/dist/modules/miniapps.d.ts +82 -0
- package/dist/modules/miniapps.d.ts.map +1 -0
- package/dist/modules/miniapps.js +58 -0
- package/dist/modules/miniapps.js.map +1 -0
- package/dist/modules/navigation.d.ts +332 -0
- package/dist/modules/navigation.d.ts.map +1 -0
- package/dist/modules/navigation.js +387 -0
- package/dist/modules/navigation.js.map +1 -0
- package/dist/modules/permissions.d.ts +58 -0
- package/dist/modules/permissions.d.ts.map +1 -0
- package/dist/modules/permissions.js +66 -0
- package/dist/modules/permissions.js.map +1 -0
- package/dist/modules/phone.d.ts +95 -0
- package/dist/modules/phone.d.ts.map +1 -0
- package/dist/modules/phone.js +110 -0
- package/dist/modules/phone.js.map +1 -0
- package/dist/modules/pivots/engine.d.ts +169 -0
- package/dist/modules/pivots/engine.d.ts.map +1 -0
- package/dist/modules/pivots/engine.js +778 -0
- package/dist/modules/pivots/engine.js.map +1 -0
- package/dist/modules/pivots/geometry.d.ts +84 -0
- package/dist/modules/pivots/geometry.d.ts.map +1 -0
- package/dist/modules/pivots/geometry.js +371 -0
- package/dist/modules/pivots/geometry.js.map +1 -0
- package/dist/modules/pivots/instructions.d.ts +139 -0
- package/dist/modules/pivots/instructions.d.ts.map +1 -0
- package/dist/modules/pivots/instructions.js +281 -0
- package/dist/modules/pivots/instructions.js.map +1 -0
- package/dist/modules/speaker.d.ts +175 -0
- package/dist/modules/speaker.d.ts.map +1 -0
- package/dist/modules/speaker.js +249 -0
- package/dist/modules/speaker.js.map +1 -0
- package/dist/modules/speakers.d.ts +29 -0
- package/dist/modules/speakers.d.ts.map +1 -0
- package/dist/modules/speakers.js +38 -0
- package/dist/modules/speakers.js.map +1 -0
- package/dist/modules/storage.d.ts +50 -0
- package/dist/modules/storage.d.ts.map +1 -0
- package/dist/modules/storage.js +99 -0
- package/dist/modules/storage.js.map +1 -0
- package/dist/modules/stream.d.ts +133 -0
- package/dist/modules/stream.d.ts.map +1 -0
- package/dist/modules/stream.js +53 -0
- package/dist/modules/stream.js.map +1 -0
- package/dist/modules/system.d.ts +71 -0
- package/dist/modules/system.d.ts.map +1 -0
- package/dist/modules/system.js +65 -0
- package/dist/modules/system.js.map +1 -0
- package/dist/modules/transcription.d.ts +99 -0
- package/dist/modules/transcription.d.ts.map +1 -0
- package/dist/modules/transcription.js +126 -0
- package/dist/modules/transcription.js.map +1 -0
- package/dist/modules/translation.d.ts +65 -0
- package/dist/modules/translation.d.ts.map +1 -0
- package/dist/modules/translation.js +121 -0
- package/dist/modules/translation.js.map +1 -0
- package/dist/modules/ui.d.ts +186 -0
- package/dist/modules/ui.d.ts.map +1 -0
- package/dist/modules/ui.js +289 -0
- package/dist/modules/ui.js.map +1 -0
- package/dist/protocol.d.ts +390 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +419 -0
- package/dist/protocol.js.map +1 -0
- package/dist/react/MiniappHeader.d.ts +44 -0
- package/dist/react/MiniappHeader.d.ts.map +1 -0
- package/dist/react/MiniappHeader.js +32 -0
- package/dist/react/MiniappHeader.js.map +1 -0
- package/dist/react/MiniappProvider.d.ts +33 -0
- package/dist/react/MiniappProvider.d.ts.map +1 -0
- package/dist/react/MiniappProvider.js +15 -0
- package/dist/react/MiniappProvider.js.map +1 -0
- package/dist/react/capsuleHeaderLayout.d.ts +3 -0
- package/dist/react/capsuleHeaderLayout.d.ts.map +1 -0
- package/dist/react/capsuleHeaderLayout.js +5 -0
- package/dist/react/capsuleHeaderLayout.js.map +1 -0
- package/dist/react/index.d.ts +13 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +9 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/useCapabilities.d.ts +26 -0
- package/dist/react/useCapabilities.d.ts.map +1 -0
- package/dist/react/useCapabilities.js +27 -0
- package/dist/react/useCapabilities.js.map +1 -0
- package/dist/react/useCapsuleHeaderStyle.d.ts +27 -0
- package/dist/react/useCapsuleHeaderStyle.d.ts.map +1 -0
- package/dist/react/useCapsuleHeaderStyle.js +39 -0
- package/dist/react/useCapsuleHeaderStyle.js.map +1 -0
- package/dist/react/useColorScheme.d.ts +18 -0
- package/dist/react/useColorScheme.d.ts.map +1 -0
- package/dist/react/useColorScheme.js +24 -0
- package/dist/react/useColorScheme.js.map +1 -0
- package/dist/react/useConnected.d.ts +17 -0
- package/dist/react/useConnected.d.ts.map +1 -0
- package/dist/react/useConnected.js +39 -0
- package/dist/react/useConnected.js.map +1 -0
- package/dist/react/useRpc.d.ts +29 -0
- package/dist/react/useRpc.d.ts.map +1 -0
- package/dist/react/useRpc.js +82 -0
- package/dist/react/useRpc.js.map +1 -0
- package/dist/react/useSafeArea.d.ts +21 -0
- package/dist/react/useSafeArea.d.ts.map +1 -0
- package/dist/react/useSafeArea.js +22 -0
- package/dist/react/useSafeArea.js.map +1 -0
- package/dist/session.d.ts +355 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +688 -0
- package/dist/session.js.map +1 -0
- package/dist/sub-path-types.test-d.d.ts +40 -0
- package/dist/sub-path-types.test-d.d.ts.map +1 -0
- package/dist/sub-path-types.test-d.js +37 -0
- package/dist/sub-path-types.test-d.js.map +1 -0
- package/dist/transport/auto.d.ts +35 -0
- package/dist/transport/auto.d.ts.map +1 -0
- package/dist/transport/auto.js +124 -0
- package/dist/transport/auto.js.map +1 -0
- package/dist/transport/dispatch.d.ts +43 -0
- package/dist/transport/dispatch.d.ts.map +1 -0
- package/dist/transport/dispatch.js +91 -0
- package/dist/transport/dispatch.js.map +1 -0
- package/dist/transport/local-socket.d.ts +28 -0
- package/dist/transport/local-socket.d.ts.map +1 -0
- package/dist/transport/local-socket.js +80 -0
- package/dist/transport/local-socket.js.map +1 -0
- package/dist/transport/mock.d.ts +54 -0
- package/dist/transport/mock.d.ts.map +1 -0
- package/dist/transport/mock.js +210 -0
- package/dist/transport/mock.js.map +1 -0
- package/dist/transport/postmessage.d.ts +36 -0
- package/dist/transport/postmessage.d.ts.map +1 -0
- package/dist/transport/postmessage.js +78 -0
- package/dist/transport/postmessage.js.map +1 -0
- package/dist/transport/types.d.ts +25 -0
- package/dist/transport/types.d.ts.map +1 -0
- package/dist/transport/types.js +11 -0
- package/dist/transport/types.js.map +1 -0
- package/dist/ui/index.d.ts +107 -0
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +32 -0
- package/dist/ui/index.js.map +1 -0
- package/package.json +88 -0
- package/src/background/index.ts +177 -0
- package/src/background/register.ts +89 -0
- package/src/dev-reload.ts +59 -0
- package/src/envelope.ts +54 -0
- package/src/globals.ts +62 -0
- package/src/hardware.ts +25 -0
- package/src/index.ts +216 -0
- package/src/modules/actions.ts +189 -0
- package/src/modules/ai.ts +281 -0
- package/src/modules/auth.ts +68 -0
- package/src/modules/base64.ts +87 -0
- package/src/modules/blob.ts +341 -0
- package/src/modules/camera.ts +258 -0
- package/src/modules/cloud.ts +94 -0
- package/src/modules/dashboard.ts +51 -0
- package/src/modules/display.ts +214 -0
- package/src/modules/events.ts +318 -0
- package/src/modules/glasses.ts +58 -0
- package/src/modules/heading.ts +23 -0
- package/src/modules/imu.ts +44 -0
- package/src/modules/input.ts +87 -0
- package/src/modules/keys.ts +46 -0
- package/src/modules/languages.ts +72 -0
- package/src/modules/led.ts +61 -0
- package/src/modules/location.ts +39 -0
- package/src/modules/memory.ts +224 -0
- package/src/modules/mic.ts +103 -0
- package/src/modules/miniapps.ts +103 -0
- package/src/modules/navigation.ts +674 -0
- package/src/modules/permissions.ts +83 -0
- package/src/modules/phone.ts +155 -0
- package/src/modules/pivots/engine.ts +863 -0
- package/src/modules/pivots/geometry.ts +409 -0
- package/src/modules/pivots/instructions.ts +341 -0
- package/src/modules/speaker.ts +347 -0
- package/src/modules/speakers.ts +40 -0
- package/src/modules/storage.ts +109 -0
- package/src/modules/stream.ts +168 -0
- package/src/modules/system.ts +113 -0
- package/src/modules/transcription.ts +180 -0
- package/src/modules/translation.ts +156 -0
- package/src/modules/ui.ts +481 -0
- package/src/protocol.ts +482 -0
- package/src/react/MiniappHeader.tsx +114 -0
- package/src/react/MiniappProvider.tsx +50 -0
- package/src/react/capsuleHeaderLayout.ts +11 -0
- package/src/react/index.ts +12 -0
- package/src/react/useCapabilities.ts +29 -0
- package/src/react/useCapsuleHeaderStyle.ts +55 -0
- package/src/react/useColorScheme.ts +26 -0
- package/src/react/useConnected.ts +47 -0
- package/src/react/useRpc.ts +103 -0
- package/src/react/useSafeArea.ts +36 -0
- package/src/session.ts +969 -0
- package/src/sub-path-types.test-d.ts +60 -0
- package/src/transport/auto.ts +143 -0
- package/src/transport/dispatch.ts +106 -0
- package/src/transport/local-socket.ts +91 -0
- package/src/transport/mock.ts +255 -0
- package/src/transport/postmessage.ts +95 -0
- package/src/transport/types.ts +26 -0
- package/src/ui/index.ts +129 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview ImuModule — head position + motion events.
|
|
3
|
+
*
|
|
4
|
+
* Glasses' inertial measurement unit. Exposes head-up/down position and a
|
|
5
|
+
* raw accelerometer stream (`onAccel`). Gyroscope / magnetometer / fused
|
|
6
|
+
* orientation are future work — when added they'll surface as a combined IMU
|
|
7
|
+
* event rather than extending this single-sensor accel stream.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import {MiniappRequestType, MiniappStreamType} from "../protocol"
|
|
11
|
+
import {MiniappSession} from "../session"
|
|
12
|
+
import type {AccelData, HeadPositionData, UnsubscribeFn} from "./events"
|
|
13
|
+
|
|
14
|
+
export class ImuModule {
|
|
15
|
+
constructor(private readonly session: MiniappSession) {}
|
|
16
|
+
|
|
17
|
+
onHeadPosition(handler: (data: HeadPositionData) => void): UnsubscribeFn {
|
|
18
|
+
return this.session._subscribe(MiniappStreamType.HEAD_POSITION, handler as (data: unknown) => void)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Subscribe to raw accelerometer readings (`{x, y, z}` in g) from the
|
|
23
|
+
* glasses IMU. G2 only today; on glasses without an exposed IMU stream the
|
|
24
|
+
* subscription succeeds but no events fire.
|
|
25
|
+
*/
|
|
26
|
+
onAccel(handler: (data: AccelData) => void): UnsubscribeFn {
|
|
27
|
+
return this.session._subscribe(MiniappStreamType.ACCEL_DATA, handler as (data: unknown) => void)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Explicitly enable or disable raw accelerometer streaming on the glasses.
|
|
32
|
+
*
|
|
33
|
+
* Subscribing via `onAccel` already auto-enables the sensor and unsubscribing
|
|
34
|
+
* disables it, so most callers don't need this. Use it when you want to drive
|
|
35
|
+
* the IMU directly — e.g. a diagnostic toggle. G2 only today; a no-op on
|
|
36
|
+
* glasses without an exposed IMU stream.
|
|
37
|
+
*/
|
|
38
|
+
setEnabled(enabled: boolean): Promise<void> {
|
|
39
|
+
return this.session.sendRequest<void>({
|
|
40
|
+
type: MiniappRequestType.IMU_SET_ENABLED,
|
|
41
|
+
enabled,
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview InputModule — physical control events on the glasses.
|
|
3
|
+
*
|
|
4
|
+
* Combines button + touch surfaces. Future input modes (gesture, voice
|
|
5
|
+
* command, eye tracking) will extend this module rather than spawning new
|
|
6
|
+
* top-level modules.
|
|
7
|
+
*
|
|
8
|
+
* Touch overloads:
|
|
9
|
+
*
|
|
10
|
+
* session.input.onTouch(handler)
|
|
11
|
+
* session.input.onTouch("single_tap", handler)
|
|
12
|
+
* session.input.onTouch(["swipe_up", "swipe_down"], handler)
|
|
13
|
+
*
|
|
14
|
+
* Per-gesture filtering rides on `touch_event:<gesture>` stream variants
|
|
15
|
+
* the phone runtime fans out alongside the bare `touch_event` stream.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import {MiniappRequestType, MiniappStreamType} from "../protocol"
|
|
19
|
+
import {MiniappSession} from "../session"
|
|
20
|
+
import type {ButtonPressData, TouchData, UnsubscribeFn} from "./events"
|
|
21
|
+
|
|
22
|
+
export class InputModule {
|
|
23
|
+
constructor(private readonly session: MiniappSession) {}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Declare the gestures this miniapp is handling itself, replacing any
|
|
27
|
+
* previous claim set. While a claimed gesture arrives and this app is
|
|
28
|
+
* FOREGROUND on the glasses, the host skips its default behavior for it —
|
|
29
|
+
* today that is `double_tap`, which otherwise opens the dashboard (or
|
|
30
|
+
* toggles head-up). The events themselves still arrive via `onTouch`
|
|
31
|
+
* either way; claiming only suppresses the system default.
|
|
32
|
+
*
|
|
33
|
+
* Pass `[]` to release every claim. Claims are cleared automatically when
|
|
34
|
+
* the miniapp stops, and are inert while the app is backgrounded — a
|
|
35
|
+
* background app never hijacks a system gesture.
|
|
36
|
+
*
|
|
37
|
+
* session.input.setClaimedGestures(["double_tap"]) // in-app back gesture
|
|
38
|
+
* session.input.setClaimedGestures([]) // back to system default
|
|
39
|
+
*/
|
|
40
|
+
setClaimedGestures(gestures: string[]): Promise<void> {
|
|
41
|
+
return this.session
|
|
42
|
+
.sendRequest<void>({type: MiniappRequestType.CLAIM_GESTURES, gestures})
|
|
43
|
+
.then(() => undefined)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
onButtonPress(handler: (data: ButtonPressData) => void): UnsubscribeFn {
|
|
47
|
+
return this.session._subscribe(MiniappStreamType.BUTTON_PRESS, handler as (data: unknown) => void)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Subscribe to touch events.
|
|
52
|
+
*
|
|
53
|
+
* onTouch(handler) — all touch events
|
|
54
|
+
* onTouch("single_tap", handler) — only single taps
|
|
55
|
+
* onTouch(["a","b"], handler) — multiple gestures, single subscription
|
|
56
|
+
*/
|
|
57
|
+
onTouch(handler: (data: TouchData) => void): UnsubscribeFn
|
|
58
|
+
onTouch(gesture: string, handler: (data: TouchData) => void): UnsubscribeFn
|
|
59
|
+
onTouch(gestures: string[], handler: (data: TouchData) => void): UnsubscribeFn
|
|
60
|
+
onTouch(
|
|
61
|
+
gestureOrHandler: string | string[] | ((data: TouchData) => void),
|
|
62
|
+
maybeHandler?: (data: TouchData) => void,
|
|
63
|
+
): UnsubscribeFn {
|
|
64
|
+
// Plain handler — subscribe to all touches.
|
|
65
|
+
if (typeof gestureOrHandler === "function") {
|
|
66
|
+
return this.session._subscribe(MiniappStreamType.TOUCH_EVENT, gestureOrHandler as (data: unknown) => void)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const handler = maybeHandler!
|
|
70
|
+
const gestures = Array.isArray(gestureOrHandler) ? gestureOrHandler : [gestureOrHandler]
|
|
71
|
+
if (gestures.length === 0) return () => {}
|
|
72
|
+
|
|
73
|
+
const unsubs: UnsubscribeFn[] = []
|
|
74
|
+
for (const g of gestures) {
|
|
75
|
+
unsubs.push(this.session._subscribe(`${MiniappStreamType.TOUCH_EVENT}:${g}`, handler as (data: unknown) => void))
|
|
76
|
+
}
|
|
77
|
+
return () => {
|
|
78
|
+
for (const u of unsubs) {
|
|
79
|
+
try {
|
|
80
|
+
u()
|
|
81
|
+
} catch {
|
|
82
|
+
/* ignore */
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview KeysModule — read user-supplied provider API keys.
|
|
3
|
+
*
|
|
4
|
+
* Users can enter their own provider API keys in the Glassly App
|
|
5
|
+
* (Settings > API Keys). A miniapp that declares the API_KEYS permission in
|
|
6
|
+
* miniapp.json can read the providers in {@link ApiKeyProvider}; the phone
|
|
7
|
+
* runtime rejects with PERMISSION_NOT_DECLARED otherwise.
|
|
8
|
+
*
|
|
9
|
+
* The provider set is an explicit host-side allowlist — asking for anything
|
|
10
|
+
* else (e.g. the Soniox transcription key, which is deliberately not exposed
|
|
11
|
+
* to miniapps) rejects with INVALID_ARGUMENT. Keys are device-local settings:
|
|
12
|
+
* the value travels only across the local bridge, never through any server.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import {MiniappRequestType} from "../protocol"
|
|
16
|
+
import {MiniappSession} from "../session"
|
|
17
|
+
|
|
18
|
+
/** Providers whose user-supplied keys miniapps may read. */
|
|
19
|
+
export type ApiKeyProvider = "anthropic" | "gemini" | "openai" | "elevenlabs" | "mapbox"
|
|
20
|
+
|
|
21
|
+
interface KeysGetResult {
|
|
22
|
+
key: string | null
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export class KeysModule {
|
|
26
|
+
constructor(private readonly session: MiniappSession) {}
|
|
27
|
+
|
|
28
|
+
/** True iff `API_KEYS` is declared in the miniapp's manifest. */
|
|
29
|
+
get hasPermission(): boolean {
|
|
30
|
+
return this.session._hasManifestPermission("API_KEYS")
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Fetch the user's API key for a provider. Resolves with the key, or null
|
|
35
|
+
* when the user hasn't saved one for that provider. Values are not cached —
|
|
36
|
+
* re-fetch (e.g. on retry after a 401 from the provider) to pick up a key
|
|
37
|
+
* the user edited in Settings while the miniapp was running.
|
|
38
|
+
*/
|
|
39
|
+
async get(provider: ApiKeyProvider): Promise<string | null> {
|
|
40
|
+
const result = await this.session.sendRequest<KeysGetResult>({
|
|
41
|
+
type: MiniappRequestType.KEYS_GET,
|
|
42
|
+
provider,
|
|
43
|
+
})
|
|
44
|
+
return result?.key ?? null
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Language validation at the SDK boundary (issue 021, WP2).
|
|
3
|
+
*
|
|
4
|
+
* The registry itself lives in `@glassly/cloud-protocol/languages` (single
|
|
5
|
+
* source of truth shared with the cloud). This module re-exports the types so
|
|
6
|
+
* miniapps import everything from `@glassly/miniapp`, and adds the throwing
|
|
7
|
+
* validators the typed module surfaces (`transcription.*`, `translation.*`)
|
|
8
|
+
* call on every language parameter.
|
|
9
|
+
*
|
|
10
|
+
* Contract (design doc docs/issues/021-typed-language-subscriptions):
|
|
11
|
+
* - Valid by construction: params are typed as literal unions, so TS users
|
|
12
|
+
* get autocomplete and compile errors.
|
|
13
|
+
* - Loud at runtime: JS users (or `any` casts) get a thrown
|
|
14
|
+
* `MiniappValidationError` with a suggestion, never silent fallback.
|
|
15
|
+
* - Canonical on the wire: bare codes ("fr") canonicalize to their default
|
|
16
|
+
* tag ("fr-FR") before becoming stream keys, so the phone/cloud only ever
|
|
17
|
+
* see registry tags.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import {
|
|
21
|
+
isTranscriptionLanguage,
|
|
22
|
+
suggestTranscriptionLanguage,
|
|
23
|
+
toLanguageHint,
|
|
24
|
+
toTranscriptionLanguage,
|
|
25
|
+
SUPPORTED_LANGUAGE_HINTS,
|
|
26
|
+
SUPPORTED_TRANSCRIPTION_LANGUAGES,
|
|
27
|
+
} from "@glassly/cloud-protocol/languages"
|
|
28
|
+
import type {LanguageHint, TranscriptionLanguage} from "@glassly/cloud-protocol/languages"
|
|
29
|
+
|
|
30
|
+
export {SUPPORTED_LANGUAGE_HINTS, SUPPORTED_TRANSCRIPTION_LANGUAGES, isTranscriptionLanguage}
|
|
31
|
+
export type {LanguageHint, TranscriptionLanguage}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Thrown synchronously by SDK methods when a parameter fails validation.
|
|
35
|
+
* Deliberately a hard throw (not a warning, not a silent default): an invalid
|
|
36
|
+
* language previously produced a subscription that silently transcribed the
|
|
37
|
+
* wrong language or silently never spoke (OS-1746).
|
|
38
|
+
*/
|
|
39
|
+
export class MiniappValidationError extends Error {
|
|
40
|
+
constructor(message: string) {
|
|
41
|
+
super(message)
|
|
42
|
+
this.name = "MiniappValidationError"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Canonicalize a subscription language or throw. Accepts registry tags
|
|
48
|
+
* ("fr-FR") and bare registry codes ("fr" -> "fr-FR").
|
|
49
|
+
*/
|
|
50
|
+
export function requireTranscriptionLanguage(value: string, param: string): TranscriptionLanguage {
|
|
51
|
+
const canonical = toTranscriptionLanguage(value)
|
|
52
|
+
if (canonical) return canonical
|
|
53
|
+
const suggestion = suggestTranscriptionLanguage(value)
|
|
54
|
+
throw new MiniappValidationError(
|
|
55
|
+
`${param}: unknown language ${JSON.stringify(value)}` +
|
|
56
|
+
(suggestion ? ` — did you mean ${JSON.stringify(suggestion)}?` : "") +
|
|
57
|
+
` Supported values are BCP-47 tags from SUPPORTED_TRANSCRIPTION_LANGUAGES (e.g. "en-US", "fr-FR").`,
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Normalize a language hint to the bare code the STT provider accepts, or
|
|
63
|
+
* throw. Accepts bare codes ("fr") and registry tags ("fr-FR" -> "fr").
|
|
64
|
+
*/
|
|
65
|
+
export function requireLanguageHint(value: string, param: string): LanguageHint {
|
|
66
|
+
const hint = toLanguageHint(value)
|
|
67
|
+
if (hint) return hint
|
|
68
|
+
throw new MiniappValidationError(
|
|
69
|
+
`${param}: unknown language hint ${JSON.stringify(value)}. ` +
|
|
70
|
+
`Hints are bare ISO 639-1 codes from SUPPORTED_LANGUAGE_HINTS (e.g. "en", "fr").`,
|
|
71
|
+
)
|
|
72
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview LedModule — glasses RGB LED control.
|
|
3
|
+
*
|
|
4
|
+
* API mirrors the cloud SDK's LED module. Colors are named strings
|
|
5
|
+
* (the phone maps them to per-device LED indices). Actions are "on" / "off".
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {MiniappRequestType} from "../protocol"
|
|
9
|
+
import {MiniappSession} from "../session"
|
|
10
|
+
|
|
11
|
+
export type LedColor = "red" | "green" | "blue" | "orange" | "white"
|
|
12
|
+
|
|
13
|
+
export type LedControlResult = {
|
|
14
|
+
type?: "rgb_led_control_response"
|
|
15
|
+
state: "success"
|
|
16
|
+
requestId: string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface LedControlOptions {
|
|
20
|
+
color?: LedColor
|
|
21
|
+
/** LED on duration in ms. */
|
|
22
|
+
ontime?: number
|
|
23
|
+
/** LED off duration in ms. */
|
|
24
|
+
offtime?: number
|
|
25
|
+
/** Number of on/off cycles. */
|
|
26
|
+
count?: number
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export class LedModule {
|
|
30
|
+
constructor(private readonly session: MiniappSession) {}
|
|
31
|
+
|
|
32
|
+
/** Turn an LED on with the given pattern. Resolves after the glasses acknowledge the command. */
|
|
33
|
+
async turnOn(options: LedControlOptions = {}): Promise<LedControlResult> {
|
|
34
|
+
return this.session.sendRequest<LedControlResult>({
|
|
35
|
+
type: MiniappRequestType.RGB_LED,
|
|
36
|
+
action: "on",
|
|
37
|
+
color: options.color ?? "red",
|
|
38
|
+
ontime: options.ontime ?? 1000,
|
|
39
|
+
offtime: options.offtime ?? 0,
|
|
40
|
+
count: options.count ?? 1,
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Turn all LEDs off. Resolves after the glasses acknowledge the command. */
|
|
45
|
+
async turnOff(): Promise<LedControlResult> {
|
|
46
|
+
return this.session.sendRequest<LedControlResult>({
|
|
47
|
+
type: MiniappRequestType.RGB_LED,
|
|
48
|
+
action: "off",
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Blink pattern — repeats `count` times with ontime/offtime. */
|
|
53
|
+
async blink(color: LedColor, ontime: number, offtime: number, count: number): Promise<LedControlResult> {
|
|
54
|
+
return this.turnOn({color, ontime, offtime, count})
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Solid LED for a fixed duration. */
|
|
58
|
+
async solid(color: LedColor, duration: number): Promise<LedControlResult> {
|
|
59
|
+
return this.turnOn({color, ontime: duration, offtime: 0, count: 1})
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -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
|
+
}
|