@mentra/miniapp 3.4.0-dev.999 → 3.4.1-beta.1409
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 +7 -7
- package/dist/background/index.d.ts +5 -2
- package/dist/background/index.d.ts.map +1 -1
- package/dist/background/index.js.map +1 -1
- package/dist/background/register.d.ts +3 -1
- package/dist/background/register.d.ts.map +1 -1
- package/dist/background/register.js +19 -2
- package/dist/background/register.js.map +1 -1
- package/dist/index.d.ts +6 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/modules/blob.d.ts +2 -1
- package/dist/modules/blob.d.ts.map +1 -1
- package/dist/modules/blob.js +2 -1
- package/dist/modules/blob.js.map +1 -1
- package/dist/modules/events.d.ts +16 -6
- package/dist/modules/events.d.ts.map +1 -1
- package/dist/modules/events.js +53 -47
- package/dist/modules/events.js.map +1 -1
- package/dist/modules/mic.d.ts +26 -4
- package/dist/modules/mic.d.ts.map +1 -1
- package/dist/modules/mic.js +13 -4
- package/dist/modules/mic.js.map +1 -1
- package/dist/modules/miniapps.d.ts +44 -57
- package/dist/modules/miniapps.d.ts.map +1 -1
- package/dist/modules/miniapps.js +21 -24
- package/dist/modules/miniapps.js.map +1 -1
- package/dist/modules/speaker.d.ts +41 -10
- package/dist/modules/speaker.d.ts.map +1 -1
- package/dist/modules/speaker.js +17 -6
- package/dist/modules/speaker.js.map +1 -1
- package/dist/modules/speechProcessing.d.ts +29 -0
- package/dist/modules/speechProcessing.d.ts.map +1 -0
- package/dist/modules/speechProcessing.js +22 -0
- package/dist/modules/speechProcessing.js.map +1 -0
- package/dist/modules/stream.d.ts +39 -0
- package/dist/modules/stream.d.ts.map +1 -1
- package/dist/modules/stream.js +13 -1
- package/dist/modules/stream.js.map +1 -1
- package/dist/modules/system.d.ts +8 -3
- package/dist/modules/system.d.ts.map +1 -1
- package/dist/modules/system.js +1 -1
- package/dist/modules/system.js.map +1 -1
- package/dist/modules/telemetry.d.ts +25 -0
- package/dist/modules/telemetry.d.ts.map +1 -0
- package/dist/modules/telemetry.js +61 -0
- package/dist/modules/telemetry.js.map +1 -0
- package/dist/modules/transcription.d.ts +70 -3
- package/dist/modules/transcription.d.ts.map +1 -1
- package/dist/modules/transcription.js +68 -2
- package/dist/modules/transcription.js.map +1 -1
- package/dist/protocol.d.ts +29 -15
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +30 -15
- package/dist/protocol.js.map +1 -1
- package/dist/react/MentraProvider.d.ts +13 -1
- package/dist/react/MentraProvider.d.ts.map +1 -1
- package/dist/react/MentraProvider.js +31 -1
- package/dist/react/MentraProvider.js.map +1 -1
- package/dist/react/stream-preview/PreviewConnection.d.ts +13 -0
- package/dist/react/stream-preview/PreviewConnection.d.ts.map +1 -1
- package/dist/react/stream-preview/PreviewConnection.js +40 -1
- package/dist/react/stream-preview/PreviewConnection.js.map +1 -1
- package/dist/react/stream-preview/transport.d.ts.map +1 -1
- package/dist/react/stream-preview/transport.js +2 -0
- package/dist/react/stream-preview/transport.js.map +1 -1
- package/dist/session.d.ts +59 -6
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +203 -43
- package/dist/session.js.map +1 -1
- package/dist/transport/auto.js +6 -0
- package/dist/transport/auto.js.map +1 -1
- package/dist/transport/dispatch.d.ts +2 -0
- package/dist/transport/dispatch.d.ts.map +1 -1
- package/dist/transport/dispatch.js +7 -2
- package/dist/transport/dispatch.js.map +1 -1
- package/dist/transport/local-socket.d.ts +6 -0
- package/dist/transport/local-socket.d.ts.map +1 -1
- package/dist/transport/local-socket.js +34 -2
- package/dist/transport/local-socket.js.map +1 -1
- package/dist/transport/types.d.ts +4 -1
- package/dist/transport/types.d.ts.map +1 -1
- package/dist/ui/index.d.ts +7 -4
- package/dist/ui/index.d.ts.map +1 -1
- package/dist/ui/index.js.map +1 -1
- package/package.json +2 -2
- package/src/background/index.ts +6 -3
- package/src/background/register.ts +24 -2
- package/src/index.ts +13 -3
- package/src/modules/blob.ts +2 -1
- package/src/modules/events.ts +65 -51
- package/src/modules/mic.ts +30 -4
- package/src/modules/miniapps.ts +59 -71
- package/src/modules/speaker.ts +56 -12
- package/src/modules/speechProcessing.ts +42 -0
- package/src/modules/stream.ts +44 -1
- package/src/modules/system.ts +8 -3
- package/src/modules/telemetry.ts +62 -0
- package/src/modules/transcription.ts +106 -9
- package/src/protocol.ts +32 -16
- package/src/react/MentraProvider.tsx +23 -2
- package/src/react/stream-preview/PreviewConnection.ts +54 -3
- package/src/react/stream-preview/transport.ts +4 -8
- package/src/session.ts +206 -52
- package/src/transport/auto.ts +5 -0
- package/src/transport/dispatch.ts +7 -2
- package/src/transport/local-socket.ts +30 -1
- package/src/transport/types.ts +4 -1
- package/src/ui/index.ts +7 -4
package/src/modules/miniapps.ts
CHANGED
|
@@ -7,10 +7,12 @@
|
|
|
7
7
|
* layer (invoke / handle) lives on `session.actions`, not here — these are
|
|
8
8
|
* operations on the app as a whole, not on a declared action.
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
* narrower still:
|
|
12
|
-
* the Mentra App
|
|
13
|
-
*
|
|
10
|
+
* Installing (`install`, `checkInstallCompatibility`, `uninstall`) is
|
|
11
|
+
* narrower still: only a miniapp on the Mentra App's system list, running the
|
|
12
|
+
* release the Mentra App installed for it, may install miniapps. Development
|
|
13
|
+
* builds, which may use the calls above, may not. The host installs from a
|
|
14
|
+
* miniapp URL through the same installer as every other way in, with no install
|
|
15
|
+
* sheet: the caller asks the person first.
|
|
14
16
|
*/
|
|
15
17
|
|
|
16
18
|
import {MiniappRequestType} from "../protocol"
|
|
@@ -55,10 +57,6 @@ export interface MiniappInfo {
|
|
|
55
57
|
compatibility: MiniappCompatibility
|
|
56
58
|
/** True when this package identity is backed by a ZIP in the Mentra App build. */
|
|
57
59
|
system: boolean
|
|
58
|
-
/** Store package that owns updates of this active release, when it is Store-managed. */
|
|
59
|
-
storeOwnerPackageName?: string
|
|
60
|
-
/** Store the host build assigns to update this bundled package's active release, if any. */
|
|
61
|
-
systemStoreOwnerPackageName?: string
|
|
62
60
|
/** Declared actions (empty if the miniapp declares none). */
|
|
63
61
|
actions: MiniappActionInfo[]
|
|
64
62
|
}
|
|
@@ -74,49 +72,54 @@ export interface MiniappHardwareRequirement {
|
|
|
74
72
|
description?: string
|
|
75
73
|
}
|
|
76
74
|
|
|
77
|
-
/**
|
|
75
|
+
/** A miniapp to install. */
|
|
78
76
|
export interface InstallMiniappRequest {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
bundleUrl: string
|
|
82
|
-
/** SHA-256 of the release ZIP; the host refuses any other bytes. */
|
|
83
|
-
bundleSha256: string
|
|
84
|
-
/**
|
|
85
|
-
* Bearer for `bundleUrl`, when the Store's backend requires one. The host
|
|
86
|
-
* forwards it untouched and keeps no Store address of its own: entitlement is
|
|
87
|
-
* settled between this miniapp and its backend, integrity by the SHA-256 and
|
|
88
|
-
* the bundle's publisher signature.
|
|
89
|
-
*/
|
|
90
|
-
bundleAuthorization?: string
|
|
91
|
-
/**
|
|
92
|
-
* Automatic update: never stop a running miniapp. A running or starting
|
|
93
|
-
* target defers the request with `APP_RUNNING`.
|
|
94
|
-
*/
|
|
95
|
-
onlyIfStopped?: boolean
|
|
77
|
+
/** The miniapp's URL: the HTTPS address that serves its `miniapp.json`. */
|
|
78
|
+
url: string
|
|
96
79
|
/**
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
* host does not show (the Mentra App is in the background, another prompt is
|
|
100
|
-
* open, or this miniapp was asked within the last day), still answers
|
|
101
|
-
* `APP_RUNNING`.
|
|
80
|
+
* The package the person agreed to install. When given, a URL that serves another package installs nothing and
|
|
81
|
+
* fails with `not_a_miniapp`.
|
|
102
82
|
*/
|
|
103
|
-
|
|
104
|
-
/** Minimum Mentra App version declared by the release manifest. */
|
|
105
|
-
minHostVersion?: string
|
|
106
|
-
/** Mentra Miniapp SDK version declared by the release manifest. */
|
|
107
|
-
sdkVersion?: string
|
|
108
|
-
/** Glasses hardware requirements declared by the release manifest. */
|
|
109
|
-
hardwareRequirements?: MiniappHardwareRequirement[]
|
|
110
|
-
releaseId?: string
|
|
111
|
-
channel?: string
|
|
83
|
+
packageName?: string
|
|
112
84
|
}
|
|
113
85
|
|
|
114
86
|
export interface InstallMiniappResult {
|
|
87
|
+
/**
|
|
88
|
+
* `installed`: this release installed. `opened`: nothing installed, because the miniapp is installed from this URL
|
|
89
|
+
* already, or a newer release of it is; {@link MiniappsModule.open} it to show it. `deferred`: the miniapp is
|
|
90
|
+
* running, so its update waits until it stops, or until the person answers the Mentra App's update prompt.
|
|
91
|
+
*/
|
|
92
|
+
status: "installed" | "opened" | "deferred"
|
|
115
93
|
packageName: string
|
|
94
|
+
/** The installed version: the new release, or the one that stays. */
|
|
116
95
|
version: string
|
|
117
|
-
installedByStore: string
|
|
118
96
|
}
|
|
119
97
|
|
|
98
|
+
/**
|
|
99
|
+
* Why an install failed: the `reason` of an `INSTALL_FAILED` rejection from {@link MiniappsModule.install}.
|
|
100
|
+
* - `not_a_miniapp`: the URL serves no valid `miniapp.json` or bundle.
|
|
101
|
+
* - `domain_mismatch`: the package name doesn't belong to the URL's domain.
|
|
102
|
+
* - `archived`: Mentra archived this URL; it doesn't install.
|
|
103
|
+
* - `needs_newer_app`: the miniapp needs a newer Mentra App, or hardware the glasses lack.
|
|
104
|
+
* - `access_denied`: its server refused this account, or this deployment doesn't allow installing from a URL.
|
|
105
|
+
* - `age_restricted`: the person's declared age is below the miniapp's age rating.
|
|
106
|
+
* - `network`: the URL couldn't be reached.
|
|
107
|
+
* - `cancelled`: the Mentra App signed out or switched deployments meanwhile.
|
|
108
|
+
* - `integrity`: the bundle doesn't match what `miniapp.json` names.
|
|
109
|
+
* - `signature_invalid`: the bundle's signature doesn't match the installed miniapp's publisher.
|
|
110
|
+
*/
|
|
111
|
+
export type InstallMiniappFailureReason =
|
|
112
|
+
| "not_a_miniapp"
|
|
113
|
+
| "domain_mismatch"
|
|
114
|
+
| "archived"
|
|
115
|
+
| "needs_newer_app"
|
|
116
|
+
| "access_denied"
|
|
117
|
+
| "age_restricted"
|
|
118
|
+
| "network"
|
|
119
|
+
| "cancelled"
|
|
120
|
+
| "integrity"
|
|
121
|
+
| "signature_invalid"
|
|
122
|
+
|
|
120
123
|
export interface InstallMiniappCompatibilityRequest {
|
|
121
124
|
minHostVersion?: string | null
|
|
122
125
|
sdkVersion?: string | null
|
|
@@ -127,17 +130,7 @@ export type InstallMiniappCompatibility =
|
|
|
127
130
|
| {compatible: true}
|
|
128
131
|
| {compatible: false; blocker: "host" | "sdk" | "hardware"; reason: string}
|
|
129
132
|
|
|
130
|
-
export type InstallMiniappPhase = "downloading" | "verifying" | "extracting" | "activating" | "complete"
|
|
131
|
-
|
|
132
|
-
export interface InstallMiniappProgress {
|
|
133
|
-
packageName: string
|
|
134
|
-
version: string
|
|
135
|
-
phase: InstallMiniappPhase
|
|
136
|
-
}
|
|
137
|
-
|
|
138
133
|
export class MiniappsModule {
|
|
139
|
-
private readonly progressHandlers = new Set<(progress: InstallMiniappProgress) => void>()
|
|
140
|
-
|
|
141
134
|
constructor(private readonly session: MiniappSession) {}
|
|
142
135
|
|
|
143
136
|
/**
|
|
@@ -185,24 +178,27 @@ export class MiniappsModule {
|
|
|
185
178
|
}
|
|
186
179
|
|
|
187
180
|
/**
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
181
|
+
* Install the miniapp at a miniapp URL, with no install sheet: ask the person first. The host fetches its
|
|
182
|
+
* `miniapp.json`, checks the package name against the URL's domain, registers the URL with Mentra, checks the
|
|
183
|
+
* phone can run it, and downloads, verifies and installs its bundle.
|
|
184
|
+
*
|
|
185
|
+
* Only a miniapp on the Mentra App's system list may install; any other caller gets NOT_PERMITTED. A failed
|
|
186
|
+
* install rejects with INSTALL_FAILED, whose `reason` is an {@link InstallMiniappFailureReason}.
|
|
191
187
|
*/
|
|
192
188
|
async install(request: InstallMiniappRequest): Promise<InstallMiniappResult> {
|
|
193
189
|
return this.session.sendRequest<InstallMiniappResult>(
|
|
194
190
|
{
|
|
195
|
-
...request,
|
|
196
191
|
type: MiniappRequestType.MINIAPPS_INSTALL,
|
|
192
|
+
url: request.url,
|
|
193
|
+
...(request.packageName !== undefined ? {packageName: request.packageName} : {}),
|
|
197
194
|
},
|
|
198
|
-
//
|
|
199
|
-
//
|
|
200
|
-
// still settles on the host response or session disconnect.
|
|
195
|
+
// Fetching, registering, downloading and installing can legitimately outlast the SDK's default request
|
|
196
|
+
// timeout. The request still settles on the host response or session disconnect.
|
|
201
197
|
{timeoutMs: 0},
|
|
202
198
|
)
|
|
203
199
|
}
|
|
204
200
|
|
|
205
|
-
/** Check
|
|
201
|
+
/** Check a release's Mentra App, SDK and glasses requirements against this phone. System-list miniapps only. */
|
|
206
202
|
async checkInstallCompatibility(request: InstallMiniappCompatibilityRequest): Promise<InstallMiniappCompatibility> {
|
|
207
203
|
return this.session.sendRequest<InstallMiniappCompatibility>({
|
|
208
204
|
type: MiniappRequestType.MINIAPPS_INSTALL_CHECK,
|
|
@@ -212,18 +208,10 @@ export class MiniappsModule {
|
|
|
212
208
|
})
|
|
213
209
|
}
|
|
214
210
|
|
|
215
|
-
/**
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/** @internal */
|
|
222
|
-
_deliverInstallProgress(progress: InstallMiniappProgress): void {
|
|
223
|
-
for (const handler of this.progressHandlers) handler(progress)
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
/** Uninstall a package this Store installed. Bundled Stores only. */
|
|
211
|
+
/**
|
|
212
|
+
* Uninstall a miniapp installed from a miniapp URL. A miniapp the Mentra App bundles, one a workspace manages and a
|
|
213
|
+
* development build stay, with NOT_PERMITTED. System-list miniapps only.
|
|
214
|
+
*/
|
|
227
215
|
async uninstall(packageName: string): Promise<void> {
|
|
228
216
|
await this.session.sendRequest<void>({
|
|
229
217
|
type: MiniappRequestType.MINIAPPS_UNINSTALL,
|
package/src/modules/speaker.ts
CHANGED
|
@@ -5,13 +5,15 @@
|
|
|
5
5
|
* audio chunks, VAD) lives on session.mic — the split is by I/O direction.
|
|
6
6
|
*
|
|
7
7
|
* Imperative surface:
|
|
8
|
-
* speaker.play({audioUrl}) — play an
|
|
8
|
+
* speaker.play({audioUrl}) — play an http(s) or data: URL, or one of this
|
|
9
|
+
* miniapp's blobs, via the phone's
|
|
9
10
|
* AudioPlaybackService.
|
|
10
|
-
* speaker.speak(text) — send a SPEAK request.
|
|
11
|
-
* TTS when connected and falls
|
|
12
|
-
*
|
|
11
|
+
* speaker.speak(text) — send a SPEAK request. By default the phone
|
|
12
|
+
* streams cloud TTS when connected and falls
|
|
13
|
+
* back to its on-device voice; the
|
|
14
|
+
* `processing` option picks the order.
|
|
13
15
|
* Resolves when playback completes; rejects
|
|
14
|
-
* with a TTS_* error code on
|
|
16
|
+
* with a TTS_* error code on failure.
|
|
15
17
|
* speaker.createStream(opts) — open a live PCM output stream (16-bit LE).
|
|
16
18
|
* Returns a SpeakerStreamWriter: write() PCM
|
|
17
19
|
* chunks as they arrive (e.g. from a WebSocket
|
|
@@ -38,8 +40,13 @@ import {MiniappErrorCode, MiniappRequestType} from "../protocol"
|
|
|
38
40
|
import {MiniappSession} from "../session"
|
|
39
41
|
import {bytesToBase64, toUint8Array} from "./base64"
|
|
40
42
|
import type {UnsubscribeFn} from "./events"
|
|
43
|
+
import {resolveSpeechProcessing, type SpeechProcessing} from "./speechProcessing"
|
|
41
44
|
|
|
42
45
|
export interface PlayAudioOptions {
|
|
46
|
+
/**
|
|
47
|
+
* An http(s) or `data:` URL, or the `file://` uri of one of this miniapp's
|
|
48
|
+
* blobs (`session.blob`). The host refuses any other file or scheme.
|
|
49
|
+
*/
|
|
43
50
|
audioUrl: string
|
|
44
51
|
/** Start playback at this offset in milliseconds. Defaults to zero. */
|
|
45
52
|
startPositionMs?: number
|
|
@@ -58,10 +65,17 @@ export interface SpeakOptions {
|
|
|
58
65
|
*/
|
|
59
66
|
enableSanitization?: boolean
|
|
60
67
|
/**
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
68
|
+
* Where the speech is synthesized. Default `"preferCloud"`.
|
|
69
|
+
*
|
|
70
|
+
* - `"preferCloud"`: cloud TTS while the cloud is connected, otherwise the
|
|
71
|
+
* phone's on-device voice.
|
|
72
|
+
* - `"preferLocal"`: the on-device voice when its model is ready and can say
|
|
73
|
+
* it (an explicit cloud `voice_id` cannot), otherwise cloud TTS.
|
|
74
|
+
* - `"localOnly"`: the on-device voice only; never the cloud. Rejects with
|
|
75
|
+
* `TTS_LOCAL_UNAVAILABLE` when the on-device model isn't ready.
|
|
64
76
|
*/
|
|
77
|
+
processing?: SpeechProcessing
|
|
78
|
+
/** @deprecated Use `processing: "localOnly"`. Removed in 4.0; ignored when `processing` is set. */
|
|
65
79
|
forceLocal?: boolean
|
|
66
80
|
}
|
|
67
81
|
|
|
@@ -80,6 +94,22 @@ export type SpeakerStreamSampleRate = 16000 | 24000 | 48000
|
|
|
80
94
|
export interface SpeakerStreamOptions {
|
|
81
95
|
/** PCM sample rate in Hz. Default 16000. */
|
|
82
96
|
sampleRate?: SpeakerStreamSampleRate
|
|
97
|
+
/**
|
|
98
|
+
* Open the native stream now and keep it idle until the first write, so a
|
|
99
|
+
* later sound only has to write samples. The speaker reports `idle` and other
|
|
100
|
+
* audio is left alone until then. If the audio route changes before the
|
|
101
|
+
* first write (Bluetooth or glasses connect/disconnect, a call, an audio
|
|
102
|
+
* interruption), the phone closes the stream and the next write fails with
|
|
103
|
+
* "not open"; open a fresh stream then.
|
|
104
|
+
*/
|
|
105
|
+
prewarm?: boolean
|
|
106
|
+
/**
|
|
107
|
+
* How much audio (80–500 ms) the phone queues before playback starts, and
|
|
108
|
+
* the cushion against gaps after that. Default 500. A sound shorter than
|
|
109
|
+
* this still plays once you close the stream. Use a small value such as 80
|
|
110
|
+
* for short cues that should start immediately.
|
|
111
|
+
*/
|
|
112
|
+
jitterMs?: number
|
|
83
113
|
/** Channel count. v1 is mono only. Default 1. */
|
|
84
114
|
channels?: 1
|
|
85
115
|
/** Playback volume 0..1. Default 1. */
|
|
@@ -118,7 +148,10 @@ export class SpeakerStreamWriter {
|
|
|
118
148
|
private settled = false
|
|
119
149
|
private writeChain: Promise<void> = Promise.resolve()
|
|
120
150
|
|
|
121
|
-
constructor(
|
|
151
|
+
constructor(
|
|
152
|
+
private readonly session: MiniappSession,
|
|
153
|
+
readonly streamId: string,
|
|
154
|
+
) {}
|
|
122
155
|
|
|
123
156
|
/**
|
|
124
157
|
* Append raw PCM bytes (16-bit LE). Auto-chunked. Resolves with the host's
|
|
@@ -255,8 +288,9 @@ export class SpeakerModule {
|
|
|
255
288
|
}
|
|
256
289
|
|
|
257
290
|
/**
|
|
258
|
-
* Speak text through the phone
|
|
259
|
-
*
|
|
291
|
+
* Speak text through the phone, in the cloud or on-device as
|
|
292
|
+
* `options.processing` says (default: cloud TTS when connected, then the
|
|
293
|
+
* on-device voice).
|
|
260
294
|
*
|
|
261
295
|
* Rejects with a MiniappRequestError containing a `code` field on cloud-side
|
|
262
296
|
* TTS failures: `TTS_TEXT_TOO_LONG`, `TTS_INVALID_VOICE`, `TTS_UPSTREAM_ERROR`.
|
|
@@ -268,6 +302,7 @@ export class SpeakerModule {
|
|
|
268
302
|
if ((Array.isArray(normalized) && normalized.length === 0) || normalized === "") {
|
|
269
303
|
throw {code: MiniappErrorCode.INTERNAL, message: "speak requires at least one non-empty sentence"}
|
|
270
304
|
}
|
|
305
|
+
const processing = resolveSpeechProcessing(options, "speaker.speak(options)")
|
|
271
306
|
try {
|
|
272
307
|
// Like play(): resolves only when TTS playback completes, so opt out of the
|
|
273
308
|
// default request timeout (long text can outlast it). Settled by the host
|
|
@@ -281,7 +316,9 @@ export class SpeakerModule {
|
|
|
281
316
|
volume: options.volume,
|
|
282
317
|
stopOtherAudio: options.stopOtherAudio ?? false,
|
|
283
318
|
enableSanitization: options.enableSanitization ?? true,
|
|
284
|
-
|
|
319
|
+
processing,
|
|
320
|
+
// Hosts before `processing` (Mentra App 3.4.0) read only this flag.
|
|
321
|
+
forceLocal: processing === "localOnly",
|
|
285
322
|
},
|
|
286
323
|
{timeoutMs: 0},
|
|
287
324
|
)
|
|
@@ -312,9 +349,16 @@ export class SpeakerModule {
|
|
|
312
349
|
) {
|
|
313
350
|
throw new RangeError("speaker stream volume must be between 0 and 1")
|
|
314
351
|
}
|
|
352
|
+
if (
|
|
353
|
+
options.jitterMs !== undefined &&
|
|
354
|
+
(!Number.isFinite(options.jitterMs) || options.jitterMs < 80 || options.jitterMs > 500)
|
|
355
|
+
)
|
|
356
|
+
throw new RangeError("speaker stream jitterMs must be between 80 and 500")
|
|
315
357
|
const res = await this.session.sendRequest<{streamId: string}>({
|
|
316
358
|
type: MiniappRequestType.SPEAKER_STREAM_OPEN,
|
|
317
359
|
sampleRate: options.sampleRate ?? 16000,
|
|
360
|
+
...(options.jitterMs === undefined ? {} : {jitterMs: options.jitterMs}),
|
|
361
|
+
...(options.prewarm === undefined ? {} : {prewarm: options.prewarm}),
|
|
318
362
|
channels: options.channels ?? 1,
|
|
319
363
|
volume: options.volume,
|
|
320
364
|
stopOtherAudio: options.stopOtherAudio ?? true,
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Where speech is processed: on the phone or in the cloud.
|
|
3
|
+
*
|
|
4
|
+
* Transcription listeners (`session.transcription.on` / `forLanguage`) and
|
|
5
|
+
* speech requests (`session.speaker.speak`) take the same `processing` option.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {MiniappValidationError} from "./languages"
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Where speech is processed.
|
|
12
|
+
*
|
|
13
|
+
* - `"preferCloud"` (default): the cloud; the phone's on-device models only
|
|
14
|
+
* while the cloud is unreachable.
|
|
15
|
+
* - `"preferLocal"`: on-device when a model for the language is ready,
|
|
16
|
+
* otherwise the cloud.
|
|
17
|
+
* - `"localOnly"`: on-device only; never the cloud.
|
|
18
|
+
*/
|
|
19
|
+
export type SpeechProcessing = "preferCloud" | "preferLocal" | "localOnly"
|
|
20
|
+
|
|
21
|
+
const SPEECH_PROCESSING: readonly SpeechProcessing[] = ["preferCloud", "preferLocal", "localOnly"]
|
|
22
|
+
|
|
23
|
+
/** The `processing` option, with the deprecated `forceLocal` it replaces. */
|
|
24
|
+
export interface SpeechProcessingOptions {
|
|
25
|
+
processing?: SpeechProcessing
|
|
26
|
+
/** @deprecated Use `processing: "localOnly"`. Removed in 4.0. */
|
|
27
|
+
forceLocal?: boolean
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @internal The processing an options object asks for. `processing` wins;
|
|
32
|
+
* without it, the deprecated `forceLocal: true` means `"localOnly"`.
|
|
33
|
+
* Throws `MiniappValidationError` for an unknown `processing` value.
|
|
34
|
+
*/
|
|
35
|
+
export function resolveSpeechProcessing(options: SpeechProcessingOptions, where: string): SpeechProcessing {
|
|
36
|
+
const {processing} = options
|
|
37
|
+
if (processing === undefined) return options.forceLocal === true ? "localOnly" : "preferCloud"
|
|
38
|
+
if (SPEECH_PROCESSING.includes(processing)) return processing
|
|
39
|
+
throw new MiniappValidationError(
|
|
40
|
+
`${where}: unknown processing ${JSON.stringify(processing)}. Use ${SPEECH_PROCESSING.map((value) => `"${value}"`).join(", ")}.`,
|
|
41
|
+
)
|
|
42
|
+
}
|
package/src/modules/stream.ts
CHANGED
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
* to your own ingest URL with no relay.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
import {MiniappRequestType, type PreviewErrorCode, type PreviewSource} from "../protocol"
|
|
11
|
+
import {MiniappRequestType, MiniappStreamType, type PreviewErrorCode, type PreviewSource} from "../protocol"
|
|
12
|
+
import type {UnsubscribeFn} from "./events"
|
|
12
13
|
import {MiniappSession} from "../session"
|
|
13
14
|
|
|
14
15
|
export interface StreamVideoConfig {
|
|
@@ -124,13 +125,42 @@ export interface StreamLiveStats {
|
|
|
124
125
|
temperatureC?: number
|
|
125
126
|
}
|
|
126
127
|
|
|
128
|
+
/** Who reported a {@link StreamStatus}. */
|
|
129
|
+
export type StreamStatusSource = "glasses" | "cloudflare" | "coordinator"
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* One stream status update. Statuses you can act on:
|
|
133
|
+
* - `source: "glasses"` — the glasses publisher: `streaming`, `reconnecting`,
|
|
134
|
+
* `reconnected`, `error`, `stopped`, ... with `kind`, `attempt`/`maxAttempts`
|
|
135
|
+
* on reconnects and `terminal: true` when the publisher gave up.
|
|
136
|
+
* - `source: "cloudflare"` — what the managed ingest sees, polled every 5s:
|
|
137
|
+
* `connected` / `disconnected`. Managed streams only.
|
|
138
|
+
* - `source: "coordinator"` — the phone: `connected`, `reconnecting` and
|
|
139
|
+
* `reconnected` for the WHIP phone relay (`transport: "softap_relay"`),
|
|
140
|
+
* `suspended` / `resumed` while Bluetooth to the glasses is down,
|
|
141
|
+
* `hls_ready` / `webrtc_ready` for playback, and `error` when the stream
|
|
142
|
+
* has ended and must be started again.
|
|
143
|
+
*/
|
|
127
144
|
export interface StreamStatus {
|
|
128
145
|
streamId: string
|
|
129
146
|
status: string
|
|
147
|
+
source?: StreamStatusSource
|
|
148
|
+
/** Glasses status kind (`lifecycle`, `reconnect`, `error`, `snapshot`, ...). */
|
|
149
|
+
kind?: string
|
|
150
|
+
/** Human-readable cause, when the reporter gave one. */
|
|
151
|
+
reason?: string
|
|
130
152
|
errorDetails?: string
|
|
153
|
+
/** The glasses publisher gave up; the stream will not recover by itself. */
|
|
154
|
+
terminal?: boolean
|
|
155
|
+
willRetry?: boolean
|
|
156
|
+
attempt?: number
|
|
157
|
+
maxAttempts?: number
|
|
158
|
+
/** `"softap_relay"` on WHIP relay statuses. */
|
|
159
|
+
transport?: string
|
|
131
160
|
/** Negotiated encode config — forwarded once, on the first status ack. */
|
|
132
161
|
resolvedConfig?: StreamResolvedConfig
|
|
133
162
|
stats?: StreamLiveStats
|
|
163
|
+
[key: string]: unknown
|
|
134
164
|
}
|
|
135
165
|
|
|
136
166
|
export interface StreamPreviewOptions {
|
|
@@ -321,6 +351,19 @@ export class StreamModule {
|
|
|
321
351
|
})
|
|
322
352
|
}
|
|
323
353
|
|
|
354
|
+
/**
|
|
355
|
+
* Listen for status updates on the stream this miniapp started or joined.
|
|
356
|
+
* Returns an unsubscribe function.
|
|
357
|
+
*
|
|
358
|
+
* A stream that is recovering on its own reports `reconnecting`, then
|
|
359
|
+
* `reconnected`, and keeps its `streamId` and playback URLs. A
|
|
360
|
+
* `source: "coordinator"` status of `error` means the stream has ended: call
|
|
361
|
+
* `startStream()` again, which returns new playback URLs.
|
|
362
|
+
*/
|
|
363
|
+
onStatus(handler: (status: StreamStatus) => void): UnsubscribeFn {
|
|
364
|
+
return this.session._subscribe(MiniappStreamType.STREAM_STATUS, handler as (data: unknown) => void)
|
|
365
|
+
}
|
|
366
|
+
|
|
324
367
|
/** Stop the active stream, or a specific one by `streamId`. */
|
|
325
368
|
async stop(streamId?: string): Promise<void> {
|
|
326
369
|
await this.session.sendRequest<void>({
|
package/src/modules/system.ts
CHANGED
|
@@ -9,13 +9,17 @@ import { MiniappSession } from "../session"
|
|
|
9
9
|
|
|
10
10
|
export interface ShareOptions {
|
|
11
11
|
text?: string
|
|
12
|
+
/**
|
|
13
|
+
* An http(s) link, or the `file://` uri of one of this miniapp's blobs
|
|
14
|
+
* (`session.blob`). The host refuses any other file or scheme.
|
|
15
|
+
*/
|
|
12
16
|
url?: string
|
|
13
17
|
title?: string
|
|
14
18
|
/** Base64-encoded file data for file sharing. */
|
|
15
19
|
base64?: string
|
|
16
20
|
/** MIME type when sharing base64 data. */
|
|
17
21
|
mimeType?: string
|
|
18
|
-
/**
|
|
22
|
+
/** File name when sharing base64 data: one name; path separators become `_`. */
|
|
19
23
|
filename?: string
|
|
20
24
|
}
|
|
21
25
|
|
|
@@ -25,9 +29,10 @@ export interface ShareResult {
|
|
|
25
29
|
}
|
|
26
30
|
|
|
27
31
|
export interface DownloadOptions {
|
|
28
|
-
/** URL to download from, OR base64 data. */
|
|
32
|
+
/** An http: or https: URL to download from, OR base64 data. */
|
|
29
33
|
url?: string
|
|
30
34
|
base64?: string
|
|
35
|
+
/** One file name; path separators become `_`. */
|
|
31
36
|
filename?: string
|
|
32
37
|
mimeType?: string
|
|
33
38
|
}
|
|
@@ -58,7 +63,7 @@ export class SystemModule {
|
|
|
58
63
|
return result ?? { success: false }
|
|
59
64
|
}
|
|
60
65
|
|
|
61
|
-
/** Open a URL in the system browser.
|
|
66
|
+
/** Open a URL in the system browser. Never opens local files or scripts (file:, content:, javascript:, data:). */
|
|
62
67
|
openUrl(url: string): void {
|
|
63
68
|
this.session.sendOneShot({
|
|
64
69
|
type: MiniappRequestType.OPEN_URL,
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview TelemetryModule (`session.telemetry`): a miniapp's own analytics, shown in its organization's Fleet
|
|
3
|
+
* Management.
|
|
4
|
+
*
|
|
5
|
+
* `capture(event, properties?)` sends one fire-and-forget message to the Mentra App and returns nothing. It never throws
|
|
6
|
+
* and never waits. The SDK checks nothing: the Mentra App attributes the event to this miniapp and applies the limits
|
|
7
|
+
* (names, values, 25 properties, the rate), and on a Mentra App without the `telemetry` host feature it does nothing.
|
|
8
|
+
* Before the handshake says which, it holds the latest 100 captures and sends them once it knows.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import {MiniappRequestType} from "../protocol"
|
|
12
|
+
import type {MiniappSession} from "../session"
|
|
13
|
+
|
|
14
|
+
export type TelemetryValue = string | number | boolean
|
|
15
|
+
export type TelemetryProperties = Record<string, TelemetryValue>
|
|
16
|
+
|
|
17
|
+
/** Captures held until the handshake says whether the Mentra App takes them. */
|
|
18
|
+
const MAX_HELD = 100
|
|
19
|
+
|
|
20
|
+
export class TelemetryModule {
|
|
21
|
+
private held: object[] = []
|
|
22
|
+
private waiting = false
|
|
23
|
+
|
|
24
|
+
constructor(private readonly session: MiniappSession) {}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Captures one event, in the style of PostHog: `session.telemetry.capture("call_ended", {platform: "teams",
|
|
28
|
+
* duration_s: 312})`. Names are lowercase letters, digits and underscores; values are flat. Never personal data: no
|
|
29
|
+
* names, emails, phone numbers, typed text or content.
|
|
30
|
+
*/
|
|
31
|
+
capture(event: string, properties?: TelemetryProperties): void {
|
|
32
|
+
try {
|
|
33
|
+
const message = {type: MiniappRequestType.TELEMETRY_CAPTURE, event, properties: properties ?? {}}
|
|
34
|
+
if (this.session.handshakeDone) {
|
|
35
|
+
if (this.session.hostFeatures?.telemetry === true) this.session.sendOneShot(message)
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
if (this.held.length >= MAX_HELD) this.held.shift()
|
|
39
|
+
this.held.push(message)
|
|
40
|
+
if (!this.waiting) {
|
|
41
|
+
this.waiting = true
|
|
42
|
+
const off = this.session.on("ready", () => {
|
|
43
|
+
off()
|
|
44
|
+
this.waiting = false
|
|
45
|
+
const held = this.held.splice(0)
|
|
46
|
+
if (this.session.hostFeatures?.telemetry !== true) return
|
|
47
|
+
for (const one of held) {
|
|
48
|
+
// Each on its own: one capture that cannot be sent never takes the others, or the session's other
|
|
49
|
+
// listeners, down with it.
|
|
50
|
+
try {
|
|
51
|
+
this.session.sendOneShot(one)
|
|
52
|
+
} catch {
|
|
53
|
+
// Lost.
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
} catch {
|
|
59
|
+
// Analytics never break the miniapp: a value that cannot be sent is lost.
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|