@mentra/bluetooth-sdk 3.3.0-dev.944 → 3.4.0-beta.1237

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 (174) hide show
  1. package/MIGRATION.md +61 -0
  2. package/README.md +111 -11
  3. package/android/build.gradle +60 -51
  4. package/android/gradle.properties +3 -0
  5. package/android/settings.gradle +47 -3
  6. package/android/src/main/java/com/mentra/bluetoothsdk/BesCrashReportWaiters.kt +68 -0
  7. package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkDefaults.kt +5 -2
  8. package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkModule.kt +89 -6
  9. package/android/src/main/java/com/mentra/bluetoothsdk/Bridge.kt +35 -1
  10. package/android/src/main/java/com/mentra/bluetoothsdk/DeviceManager.kt +159 -110
  11. package/android/src/main/java/com/mentra/bluetoothsdk/DeviceStore.kt +21 -0
  12. package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedChangelogCatalog.kt +2 -1
  13. package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedReleaseMetadata.kt +6 -6
  14. package/android/src/main/java/com/mentra/bluetoothsdk/MentraBluetoothSdk.kt +35 -2
  15. package/android/src/main/java/com/mentra/bluetoothsdk/TouchGesture.kt +19 -0
  16. package/android/src/main/java/com/mentra/bluetoothsdk/connection/ConnectionModels.kt +5 -0
  17. package/android/src/main/java/com/mentra/bluetoothsdk/events/BluetoothEvents.kt +16 -0
  18. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/GlassesAudioSetupPolicy.kt +64 -0
  19. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLive.kt +1002 -157
  20. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLiveOwnerLossPolicy.kt +227 -0
  21. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingAdvertisement.kt +19 -0
  22. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingReadinessPolicy.kt +94 -0
  23. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingStateMachine.kt +411 -0
  24. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingStateStore.kt +124 -0
  25. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/Nimo.kt +54 -59
  26. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasCoordinator.kt +5 -32
  27. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasEncoder.kt +8 -1
  28. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasSession.kt +3 -10
  29. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/SGCManager.kt +6 -0
  30. package/android/src/main/java/com/mentra/bluetoothsdk/status/DeviceStatus.kt +50 -0
  31. package/android/src/main/java/com/mentra/bluetoothsdk/stt/BoundedAudioQueue.kt +92 -0
  32. package/android/src/main/java/com/mentra/bluetoothsdk/stt/OnDeviceRecognizerHost.kt +169 -0
  33. package/android/src/main/java/com/mentra/bluetoothsdk/stt/STTTools.kt +74 -115
  34. package/android/src/main/java/com/mentra/bluetoothsdk/stt/SherpaOnnxTranscriber.kt +348 -357
  35. package/android/src/main/java/com/mentra/bluetoothsdk/stt/SpeechActivityDetector.kt +211 -0
  36. package/android/src/main/java/com/mentra/bluetoothsdk/stt/SpeechActivityEngine.kt +137 -0
  37. package/android/src/main/java/com/mentra/bluetoothsdk/stt/SttTextFormatter.kt +52 -0
  38. package/android/src/main/java/com/mentra/bluetoothsdk/stt/WakeWordDetector.kt +235 -0
  39. package/android/src/main/java/com/mentra/bluetoothsdk/utils/AvifExifStripper.java +2 -2
  40. package/android/src/main/java/com/mentra/bluetoothsdk/utils/BlePhotoUploadService.java +3 -3
  41. package/android/src/main/java/com/mentra/bluetoothsdk/utils/IncidentLogBleRelayNaming.java +11 -0
  42. package/android/src/main/java/com/mentra/bluetoothsdk/utils/audio/AudioRouteWatcher.kt +120 -0
  43. package/android/src/main/java/com/mentra/bluetoothsdk/utils/audio/PcmStreamPlayer.kt +181 -16
  44. package/android/src/main/java/com/mentra/bluetoothsdk/utils/audio/PcmUrlPlayback.kt +177 -0
  45. package/android/src/test/java/com/mentra/bluetoothsdk/BesCrashReportWaitersTest.kt +112 -0
  46. package/android/src/test/java/com/mentra/bluetoothsdk/DeviceManagerOwnerLossTest.kt +146 -0
  47. package/android/src/test/java/com/mentra/bluetoothsdk/GlassesStatusAudioSetupTest.kt +51 -0
  48. package/android/src/test/java/com/mentra/bluetoothsdk/GlassesStatusClassicAudioTest.kt +2 -0
  49. package/android/src/test/java/com/mentra/bluetoothsdk/TouchGestureCommandTest.kt +112 -0
  50. package/android/src/test/java/com/mentra/bluetoothsdk/WifiAdbPeerIntentTest.kt +19 -0
  51. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/GlassesAudioSetupPolicyTest.kt +65 -0
  52. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveAudioSetupReadinessTest.kt +231 -0
  53. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveGlassesReadyBurstTest.kt +141 -0
  54. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveIncidentDispatchTest.kt +183 -0
  55. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveOwnerLossPolicyTest.kt +368 -0
  56. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingAdvertisementParserTest.kt +20 -0
  57. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingReadinessPolicyTest.kt +136 -0
  58. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingStateMachineTest.kt +346 -0
  59. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveRgbLedResponseTest.kt +76 -0
  60. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasCoordinatorTest.kt +1 -56
  61. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasSessionTest.kt +0 -22
  62. package/android/src/test/java/com/mentra/bluetoothsdk/utils/IncidentLogBleRelayNamingTest.kt +23 -0
  63. package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/BoundedAudioQueueTest.kt +81 -0
  64. package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/OnDeviceRecognizerHostTest.kt +216 -0
  65. package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/STTToolsExtractionTest.kt +108 -0
  66. package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/SpeechActivityDetectorTest.kt +126 -0
  67. package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/SpeechActivityEngineTest.kt +245 -0
  68. package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/SttTextFormatterTest.kt +67 -0
  69. package/android/src/testDebug/java/com/mentra/bluetoothsdk/utils/audio/PcmUrlPlaybackTest.kt +76 -0
  70. package/build/BluetoothSdk.types.d.ts +207 -2
  71. package/build/BluetoothSdk.types.d.ts.map +1 -1
  72. package/build/BluetoothSdk.types.js.map +1 -1
  73. package/build/_private/BluetoothSdkModule.d.ts +45 -6
  74. package/build/_private/BluetoothSdkModule.d.ts.map +1 -1
  75. package/build/_private/BluetoothSdkModule.js +2 -0
  76. package/build/_private/BluetoothSdkModule.js.map +1 -1
  77. package/build/generated/changelogCatalog.d.ts +4 -1
  78. package/build/generated/changelogCatalog.d.ts.map +1 -1
  79. package/build/generated/changelogCatalog.js +5 -1
  80. package/build/generated/changelogCatalog.js.map +1 -1
  81. package/build/generated/releaseMetadata.js +6 -6
  82. package/build/generated/releaseMetadata.js.map +1 -1
  83. package/build/index.d.ts +1 -1
  84. package/build/index.d.ts.map +1 -1
  85. package/build/index.js +10 -0
  86. package/build/index.js.map +1 -1
  87. package/ios/BluetoothSdkModule.swift +84 -12
  88. package/ios/MentraBluetoothSDK.podspec +4 -0
  89. package/ios/Packages/SherpaOnnx/SherpaOnnx.swift +23 -5
  90. package/ios/Resources/SileroVad/silero_vad.onnx +0 -0
  91. package/ios/Source/BesCrashReportWaiters.swift +64 -0
  92. package/ios/Source/BluetoothSdkDefaults.swift +2 -2
  93. package/ios/Source/Bridge.swift +11 -3
  94. package/ios/Source/DeviceManager.swift +135 -18
  95. package/ios/Source/DeviceStore.swift +27 -0
  96. package/ios/Source/GeneratedChangelogCatalog.swift +2 -1
  97. package/ios/Source/GeneratedReleaseMetadata.swift +6 -6
  98. package/ios/Source/MentraBluetoothSDK.swift +51 -5
  99. package/ios/Source/TouchGesture.swift +13 -0
  100. package/ios/Source/audio/PcmStreamPlayer.swift +290 -57
  101. package/ios/Source/audio/PcmUrlPlayback.swift +231 -0
  102. package/ios/Source/audio/SpeechActivity.swift +277 -0
  103. package/ios/Source/errors/BluetoothSdkError.swift +5 -1
  104. package/ios/Source/events/BluetoothEvents.swift +45 -0
  105. package/ios/Source/internal/BleTraceLogger.swift +9 -6
  106. package/ios/Source/internal/BluetoothAvailability.swift +15 -5
  107. package/ios/Source/sgcs/GlassesAudioSetupPolicy.swift +186 -0
  108. package/ios/Source/sgcs/MentraLive.swift +1366 -212
  109. package/ios/Source/sgcs/MentraLivePairingAdvertisement.swift +260 -1
  110. package/ios/Source/sgcs/MentraLivePairingStateMachine.swift +385 -0
  111. package/ios/Source/sgcs/MentraLivePairingStateStore.swift +121 -0
  112. package/ios/Source/sgcs/Nimo.swift +10 -3
  113. package/ios/Source/sgcs/NimoCanvasCoordinator.swift +39 -9
  114. package/ios/Source/sgcs/SGCManager.swift +13 -0
  115. package/ios/Source/sgcs/Simulated.swift +2 -0
  116. package/ios/Source/status/DeviceStatus.swift +35 -0
  117. package/ios/Source/stt/STTTools.swift +13 -31
  118. package/ios/Source/stt/SherpaOnnxTranscriber.swift +204 -162
  119. package/ios/Source/stt/SileroSpeechActivity.swift +87 -0
  120. package/ios/Source/stt/WakeWordDetector.swift +145 -0
  121. package/ios/Source/types/DeviceModels.swift +8 -1
  122. package/ios/Source/utils/AudioSessionMonitor.swift +158 -5
  123. package/ios/Source/utils/BoundedWait.swift +44 -0
  124. package/ios/Source/utils/DemandDrivenAudioWorker.swift +79 -0
  125. package/ios/Source/utils/SttModelTraits.swift +62 -0
  126. package/ios/Tests/BesCrashReportTests.swift +142 -0
  127. package/ios/Tests/BluetoothAudioRouteTests.swift +82 -0
  128. package/ios/Tests/DemandDrivenAudioWorkerTests.swift +171 -0
  129. package/ios/Tests/DeviceManagerReconnectTests.swift +4 -2
  130. package/ios/Tests/GlassesAudioSetupPolicyTests.swift +197 -0
  131. package/ios/Tests/IncidentLogDispatchTests.swift +158 -0
  132. package/ios/Tests/MentraLiveAudioSetupTests.swift +209 -0
  133. package/ios/Tests/MentraLiveCommandQueueTests.swift +35 -0
  134. package/ios/Tests/MentraLiveConnectionOptionsTests.swift +55 -0
  135. package/ios/Tests/MentraLivePairingAdvertisementTests.swift +327 -0
  136. package/ios/Tests/MentraLivePairingStateMachineTests.swift +402 -0
  137. package/ios/Tests/MentraLiveSessionReadinessTests.swift +497 -26
  138. package/ios/Tests/NimoCanvasTransportTests.swift +58 -0
  139. package/ios/Tests/PcmStreamTests.swift +299 -0
  140. package/ios/Tests/SpeechActivityTests.swift +238 -0
  141. package/ios/Tests/SttModelTraitsTests.swift +62 -0
  142. package/ios/Tests/TouchGestureCommandTests.swift +87 -0
  143. package/ios/Tests/WifiAdbDispatchTests.swift +118 -0
  144. package/package.json +3 -2
  145. package/plugin/build/withAndroid.js +9 -11
  146. package/plugin/build/withKotlinVersion.d.ts +2 -0
  147. package/plugin/build/withKotlinVersion.js +46 -0
  148. package/src/BluetoothSdk.types.ts +216 -1
  149. package/src/_private/BluetoothSdkModule.ts +49 -5
  150. package/src/generated/changelogCatalog.ts +5 -1
  151. package/src/generated/releaseMetadata.ts +6 -6
  152. package/src/index.ts +24 -0
  153. package/android/silero/LICENSE.md +0 -17
  154. package/android/silero/build.gradle +0 -50
  155. package/android/silero/proguard-rules.pro +0 -24
  156. package/android/silero/src/androidTest/assets/hello.wav +0 -0
  157. package/android/silero/src/androidTest/java/com/konovalov/vad/silero/VadSileroTest.kt +0 -79
  158. package/android/silero/src/main/java/com/konovalov/vad/silero/Vad.kt +0 -160
  159. package/android/silero/src/main/java/com/konovalov/vad/silero/VadSilero.kt +0 -449
  160. package/android/silero/src/main/java/com/konovalov/vad/silero/config/FrameSize.kt +0 -15
  161. package/android/silero/src/main/java/com/konovalov/vad/silero/config/Mode.kt +0 -14
  162. package/android/silero/src/main/java/com/konovalov/vad/silero/config/SampleRate.kt +0 -12
  163. package/android/silero/src/main/java/com/konovalov/vad/silero/utils/AudioUtils.kt +0 -47
  164. package/android/silero/src/main/java/com/konovalov/vad/silero/utils/TensorMap.kt +0 -41
  165. package/android/silero/src/test/java/com/konovalov/vad/silero/utils/AudioUtilsTest.kt +0 -44
  166. package/android/src/debug/java/com/mentra/bluetoothsdk/sgcs/NimoDiagnostics.kt +0 -368
  167. package/android/src/debug/java/com/mentra/bluetoothsdk/sgcs/NimoFramebufferProtocol.kt +0 -156
  168. package/android/src/main/java/com/mentra/bluetoothsdk/stt/VadGateSpeechPolicy.kt +0 -229
  169. package/android/src/release/java/com/mentra/bluetoothsdk/sgcs/NimoDiagnostics.kt +0 -20
  170. package/android/src/testDebug/java/com/mentra/bluetoothsdk/sgcs/NimoDiagnosticsTest.kt +0 -287
  171. package/android/src/testDebug/java/com/mentra/bluetoothsdk/sgcs/NimoFramebufferProtocolTest.kt +0 -127
  172. package/android/src/testDebug/java/com/mentra/bluetoothsdk/sgcs/NimoLifecycleTest.kt +0 -288
  173. /package/android/{silero/src/main/assets/LICENSE → src/main/assets/vad/LICENSE.silero_vad} +0 -0
  174. /package/android/{silero/src/main/assets → src/main/assets/vad}/silero_vad.onnx +0 -0
@@ -85,6 +85,8 @@ struct ViewState {
85
85
  // Check if device is paired (don't activate to preserve A2DP music playback)
86
86
  let isPaired = AudioSessionMonitor.isDevicePaired(devicePattern: audioDevicePattern)
87
87
 
88
+ publishClassicAudioProfiles(devicePattern: audioDevicePattern)
89
+
88
90
  if isPaired {
89
91
  // Device is paired! Don't activate it - let PhoneMic.swift activate when recording starts
90
92
  Bridge.log("Audio: Mentra Live is paired (preserving A2DP for music)")
@@ -98,6 +100,7 @@ struct ViewState {
98
100
  AudioSessionMonitor.startMonitoring(devicePattern: audioDevicePattern) {
99
101
  [weak self] (connected: Bool, _: String?) in
100
102
  guard let self = self else { return }
103
+ self.publishClassicAudioProfiles(devicePattern: audioDevicePattern)
101
104
 
102
105
  if connected {
103
106
  Bridge.log("Audio: Device paired and connected")
@@ -133,6 +136,22 @@ struct ViewState {
133
136
  set { DeviceStore.shared.apply("bluetooth", "default_wearable", newValue) }
134
137
  }
135
138
 
139
+ /// Clears the retired pre-v4 owner-lost setting. The Mentra Live pairing state is native
140
+ /// (`MentraLivePairingStateStore`) and never rides the settings replay.
141
+ private func clearOwnerLost() {
142
+ guard DeviceStore.shared.get("bluetooth", "mentra_live_owner_lost") as? Bool == true else { return }
143
+ DeviceStore.shared.apply("bluetooth", "mentra_live_owner_lost", false)
144
+ Bridge.saveSetting("mentra_live_owner_lost", false)
145
+ }
146
+
147
+ /// The saved glasses' firmware is no longer known once they are forgotten. The next glasses
148
+ /// report it again with their first `pairing_info`.
149
+ private func clearSecureFirmware() {
150
+ guard DeviceStore.shared.get("bluetooth", "mentra_live_secure_firmware") as? Bool == true else { return }
151
+ DeviceStore.shared.apply("bluetooth", "mentra_live_secure_firmware", false)
152
+ Bridge.saveSetting("mentra_live_secure_firmware", false)
153
+ }
154
+
136
155
  private var pendingWearable: String {
137
156
  get { DeviceStore.shared.get("bluetooth", "pending_wearable") as? String ?? "" }
138
157
  set { DeviceStore.shared.apply("bluetooth", "pending_wearable", newValue) }
@@ -203,14 +222,6 @@ struct ViewState {
203
222
  set { DeviceStore.shared.apply("bluetooth", "sensing_enabled", newValue) }
204
223
  }
205
224
 
206
- /// Phone-side VAD gating switch. Default is OFF (VAD runs) so that the
207
- /// coordinator can drive per-utterance offline/online STT switching from
208
- /// `vad_status` events. Set to `true` only as an emergency kill-switch.
209
- private var bypassVad: Bool {
210
- get { DeviceStore.shared.get("bluetooth", "bypass_vad") as? Bool ?? false }
211
- set { DeviceStore.shared.apply("bluetooth", "bypass_vad", newValue) }
212
- }
213
-
214
225
  private var localSttFallbackActive: Bool {
215
226
  get { DeviceStore.shared.get("bluetooth", "local_stt_fallback_active") as? Bool ?? false }
216
227
  set { DeviceStore.shared.apply("bluetooth", "local_stt_fallback_active", newValue) }
@@ -253,6 +264,26 @@ struct ViewState {
253
264
  set { DeviceStore.shared.apply("glasses", "bluetoothClassicConnected", newValue) }
254
265
  }
255
266
 
267
+ /// An HFP input is available or a matching Bluetooth output is active.
268
+ private var glassesBluetoothClassicProfilesConnected: Bool {
269
+ get { DeviceStore.shared.get("glasses", "bluetoothClassicProfilesConnected") as? Bool ?? false }
270
+ set { DeviceStore.shared.apply("glasses", "bluetoothClassicProfilesConnected", newValue) }
271
+ }
272
+
273
+ /// A matching Bluetooth output is the active audio route.
274
+ private var glassesBluetoothAudioRouted: Bool {
275
+ get { DeviceStore.shared.get("glasses", "bluetoothAudioRouted") as? Bool ?? false }
276
+ set { DeviceStore.shared.apply("glasses", "bluetoothAudioRouted", newValue) }
277
+ }
278
+
279
+ #if !os(macOS)
280
+ private func publishClassicAudioProfiles(devicePattern: String) {
281
+ let profiles = AudioSessionMonitor.observeProfiles(devicePattern: devicePattern)
282
+ glassesBluetoothClassicProfilesConnected = profiles.profilesConnected
283
+ glassesBluetoothAudioRouted = profiles.audioRouted
284
+ }
285
+ #endif
286
+
256
287
  private var micRanking: [String] {
257
288
  get {
258
289
  DeviceStore.shared.get("bluetooth", "micRanking") as? [String] ?? MicMap.map["auto"]!
@@ -519,6 +550,11 @@ struct ViewState {
519
550
  }
520
551
 
521
552
  func handlePcm(_ pcmData: Data) {
553
+ // The wake word, phone-side speech activity, and local STT all hear the same 16 kHz mono PCM.
554
+ #if !os(macOS) && (!SWIFT_PACKAGE || MENTRA_FEATURE_LOCAL_STT)
555
+ WakeWordDetector.shared.accept(pcmData)
556
+ SpeechActivityMonitor.shared.accept(pcmData)
557
+ #endif
522
558
  handleSendingPcm(pcmData)
523
559
 
524
560
  // Send PCM to local transcriber.
@@ -942,17 +978,23 @@ struct ViewState {
942
978
 
943
979
  if audioDevicePattern.isEmpty || audioDevicePattern == DeviceTypes.SIMULATED {
944
980
  glassesBluetoothClassicConnected = false
981
+ glassesBluetoothClassicProfilesConnected = false
982
+ glassesBluetoothAudioRouted = false
945
983
  Bridge.log("MAN: Audio device pattern is empty or simulated, returning")
946
984
  return
947
985
  }
948
986
 
949
987
  #if os(macOS)
950
988
  glassesBluetoothClassicConnected = AudioSessionMonitor.isAudioDeviceConnected(devicePattern: audioDevicePattern)
989
+ // macOS only sees active audio devices, so every fact collapses to the same value.
990
+ glassesBluetoothClassicProfilesConnected = glassesBluetoothClassicConnected
991
+ glassesBluetoothAudioRouted = glassesBluetoothClassicConnected
951
992
  otherBtConnected = AudioSessionMonitor.isOtherAudioDeviceConnected(devicePattern: audioDevicePattern)
952
993
  #else
953
994
  // A connected HFP input remains eligible even while another output is
954
995
  // selected. Inspect available inputs as well as the active A2DP route.
955
996
  glassesBluetoothClassicConnected = AudioSessionMonitor.isDevicePaired(devicePattern: audioDevicePattern)
997
+ publishClassicAudioProfiles(devicePattern: audioDevicePattern)
956
998
  otherBtConnected = AudioSessionMonitor.isOtherAudioDeviceConnected(devicePattern: audioDevicePattern)
957
999
  #endif
958
1000
  }
@@ -963,12 +1005,33 @@ struct ViewState {
963
1005
  updateMicState()
964
1006
  }
965
1007
 
966
- func restartTranscriber() {
1008
+ /// Whether on-device transcription currently has `path` loaded. Never waits for a load.
1009
+ func isSttModelLoaded(_ path: String) -> Bool {
1010
+ #if !os(macOS) && (!SWIFT_PACKAGE || MENTRA_FEATURE_LOCAL_STT)
1011
+ return transcriber.isModelLoaded(path)
1012
+ #else
1013
+ return false
1014
+ #endif
1015
+ }
1016
+
1017
+ /// Reload the selected model if on-device transcription is in demand. Returns false only
1018
+ /// when that reload failed; true once it loaded or when there is no demand.
1019
+ func restartTranscriber() async -> Bool {
967
1020
  #if !os(macOS) && (!SWIFT_PACKAGE || MENTRA_FEATURE_LOCAL_STT)
968
- Bridge.log("MAN: Restarting SherpaOnnxTranscriber via command")
969
- transcriber.restart()
1021
+ Bridge.log("MAN: Restarting SherpaOnnxTranscriber via command")
1022
+ return await transcriber.restart()
970
1023
  #else
971
- Bridge.log("MAN: Local STT is not included in this SwiftPM build")
1024
+ Bridge.log("MAN: Local STT is not included in this SwiftPM build")
1025
+ return true
1026
+ #endif
1027
+ }
1028
+
1029
+ /// End the current on-device utterance. See `SherpaOnnxTranscriber.finishUtterance`.
1030
+ func finishTranscription() async -> String? {
1031
+ #if !os(macOS) && (!SWIFT_PACKAGE || MENTRA_FEATURE_LOCAL_STT)
1032
+ return await transcriber.finishUtterance()
1033
+ #else
1034
+ return nil
972
1035
  #endif
973
1036
  }
974
1037
 
@@ -1526,6 +1589,13 @@ struct ViewState {
1526
1589
  try driver.sendIncidentId(incidentId, apiBaseUrl: apiBaseUrl)
1527
1590
  }
1528
1591
 
1592
+ func sendBesCrashReported(incidentKey: String, reportId: String) throws {
1593
+ guard let driver = sgc else {
1594
+ throw BluetoothSdkError(code: "glasses_not_connected", message: "Cannot report the BES crash because glasses are not connected.")
1595
+ }
1596
+ try driver.sendBesCrashReported(incidentKey: incidentKey, reportId: reportId)
1597
+ }
1598
+
1529
1599
  func sendWifiCredentials(_ ssid: String, _ password: String) {
1530
1600
  Bridge.log("MAN: Sending wifi credentials: \(ssid)")
1531
1601
  sgc?.sendWifiCredentials(ssid, password)
@@ -1540,6 +1610,15 @@ struct ViewState {
1540
1610
  sgc?.sendHotspotState(enabled)
1541
1611
  }
1542
1612
 
1613
+ func setWifiAdbState(_ enabled: Bool, expectedBluetoothMac: String?) throws {
1614
+ guard let expectedBluetoothMac else { setWifiAdbState(enabled); return }
1615
+ guard let live = sgc as? MentraLive else {
1616
+ throw BluetoothSdkError(code: "glasses_not_connected", message: "Mentra Live glasses are not connected.")
1617
+ }
1618
+ // Capture one driver; its own session identity guards the actual queue insertion.
1619
+ try live.sendWifiAdbState(enabled, expectedBluetoothMac: expectedBluetoothMac)
1620
+ }
1621
+
1543
1622
  func setWifiAdbState(_ enabled: Bool) {
1544
1623
  Bridge.log("MAN: 🔧 Setting glasses Wi-Fi ADB state: \(enabled)")
1545
1624
  sgc?.sendWifiAdbState(enabled)
@@ -1597,6 +1676,10 @@ struct ViewState {
1597
1676
  try liveSgc().sendGalleryServerEnabled(requestId: requestId, enabled: enabled)
1598
1677
  }
1599
1678
 
1679
+ func sendTouchGestureDefaultBehaviorEnabled(requestId: String, gesture: TouchGesture, enabled: Bool) throws {
1680
+ try liveSgc().sendTouchGestureDefaultBehaviorEnabled(requestId: requestId, gesture: gesture, enabled: enabled)
1681
+ }
1682
+
1600
1683
  func sendGalleryMode(requestId: String, enabled: Bool) throws {
1601
1684
  try liveSgc().sendGalleryMode(requestId: requestId, active: enabled)
1602
1685
  }
@@ -1861,9 +1944,18 @@ struct ViewState {
1861
1944
  }
1862
1945
  initSGC(defaultWearable)
1863
1946
  (sgc as? MentraLive)?.setRequiresAncs(requiresAncs)
1864
- if let live = sgc as? MentraLive, live.isPairingYieldActive() {
1865
- Bridge.log("MAN: connectDefault skipped — Mentra Live pairing yield active")
1866
- return
1947
+ if let live = sgc as? MentraLive {
1948
+ let pairingState = MentraLivePairingStateStore.shared
1949
+ if pairingState.isRejected {
1950
+ Bridge.log("MAN: connectDefault skipped — Mentra Live pairing_rejected (Pair Again or forget)")
1951
+ return
1952
+ }
1953
+ if pairingState.isPaused {
1954
+ // The manager watches the advertisement and resumes on its own.
1955
+ Bridge.log("MAN: connectDefault deferred — Mentra Live pairing_mode")
1956
+ live.connectById(reconnectTarget)
1957
+ return
1958
+ }
1867
1959
  }
1868
1960
  searching = true
1869
1961
  sgc?.connectById(reconnectTarget)
@@ -1885,21 +1977,21 @@ struct ViewState {
1885
1977
  }
1886
1978
 
1887
1979
  func connectByName(_ dName: String, requiresAncs: Bool = true) {
1888
- Bridge.log("MAN: Connecting to wearable: \(dName)")
1889
1980
  var name = dName
1890
1981
 
1891
1982
  // use stored device name if available:
1892
1983
  if dName.isEmpty && !deviceName.isEmpty {
1893
1984
  name = deviceName
1894
1985
  }
1986
+ Bridge.log("PAIRFLOW: connect_by_name requested=\(dName) resolved=\(name)")
1895
1987
 
1896
1988
  if pendingWearable.isEmpty, defaultWearable.isEmpty {
1897
- Bridge.log("MAN: No pending or default wearable, returning")
1989
+ Bridge.log("PAIRFLOW: connect_by_name abort reason=no_wearable")
1898
1990
  return
1899
1991
  }
1900
1992
 
1901
1993
  if pendingWearable.isEmpty, !defaultWearable.isEmpty {
1902
- Bridge.log("MAN: No pending wearable, using default wearable: \(defaultWearable)")
1994
+ Bridge.log("PAIRFLOW: connect_by_name pending=\(defaultWearable)")
1903
1995
  pendingWearable = defaultWearable
1904
1996
  }
1905
1997
 
@@ -1910,6 +2002,21 @@ struct ViewState {
1910
2002
  return
1911
2003
  }
1912
2004
 
2005
+ // Only an existing Mentra Live manager is reused. Calling initSGC first would swap out a
2006
+ // manager of another model here, before the queued handoff below disposes of it.
2007
+ if pendingWearable.contains(DeviceTypes.LIVE), let live = sgc as? MentraLive, !live.isManagerKilled {
2008
+ // The pairing scan already found this peripheral. Destroying the
2009
+ // manager here drops it, and the glasses are no longer discoverable
2010
+ // after the BLE bond, so the replacement scan never sees them.
2011
+ Bridge.log("PAIRFLOW: connect_by_name decision=reuse_manager name=\(name)")
2012
+ searching = true
2013
+ pendingDeviceName = name
2014
+ live.setRequiresAncs(requiresAncs)
2015
+ live.connectById(name)
2016
+ return
2017
+ }
2018
+
2019
+ Bridge.log("PAIRFLOW: connect_by_name decision=new_manager name=\(name)")
1913
2020
  Task {
1914
2021
  disconnect(clearPendingConnection: false)
1915
2022
  try? await Task.sleep(nanoseconds: 100 * 1_000_000) // 100ms
@@ -1950,6 +2057,8 @@ struct ViewState {
1950
2057
  #if os(macOS)
1951
2058
  audioRouteObserver = nil
1952
2059
  glassesBluetoothClassicConnected = false
2060
+ glassesBluetoothClassicProfilesConnected = false
2061
+ glassesBluetoothAudioRouted = false
1953
2062
  otherBtConnected = false
1954
2063
  #endif
1955
2064
  sgc?.clearDisplay() // clear the screen
@@ -2026,6 +2135,14 @@ struct ViewState {
2026
2135
 
2027
2136
  func forget() {
2028
2137
  Bridge.log("MAN: Forgetting smart glasses")
2138
+ MentraLivePairingStateStore.shared.update("forget") { $0.onForget() }
2139
+ clearOwnerLost()
2140
+ clearSecureFirmware()
2141
+ // With no connection object, MentraLive.forget() can't run. Only clear Live's saved
2142
+ // identity when Live is the target: forgetting G1/G2 must not touch a Live unit's.
2143
+ if sgc == nil, defaultWearable.contains(DeviceTypes.LIVE) || pendingWearable.contains(DeviceTypes.LIVE) {
2144
+ MentraLive.clearSavedPeripheral()
2145
+ }
2029
2146
  // Call forget first to stop timers/handlers/reconnect logic
2030
2147
  sgc?.forget()
2031
2148
  disconnect()
@@ -31,6 +31,8 @@ class DeviceStore {
31
31
  store.set("glasses", "micEnabled", false)
32
32
  store.set("glasses", "voiceActivityDetectionEnabled", BluetoothSdkDefaults.voiceActivityDetectionEnabled)
33
33
  store.set("glasses", "bluetoothClassicConnected", false)
34
+ store.set("glasses", "bluetoothClassicProfilesConnected", false)
35
+ store.set("glasses", "bluetoothAudioRouted", false)
34
36
  store.set("glasses", "caseRemoved", true)
35
37
  store.set("glasses", "caseOpen", true)
36
38
  store.set("glasses", "caseCharging", false)
@@ -59,6 +61,7 @@ class DeviceStore {
59
61
  store.set("glasses", "signalStrength", -1)
60
62
  store.set("glasses", "signalStrengthUpdatedAt", 0)
61
63
  store.set("glasses", "ringSignalStrength", -1)
64
+ store.set("glasses", "audioSetup", GlassesAudioSetupState.idle.toMap())
62
65
 
63
66
  // CORE STATE:
64
67
  store.set("bluetooth", "systemMicUnavailable", false)
@@ -144,10 +147,34 @@ class DeviceStore {
144
147
  }
145
148
  }
146
149
 
150
+ /// Publishes `GlassesStatus.audioSetup` and `audio_setup_changed` when the state changed.
151
+ @discardableResult
152
+ func publishAudioSetup(_ state: GlassesAudioSetupState) -> Bool {
153
+ guard GlassesAudioSetupState(map: store.get("glasses", "audioSetup")) != state else { return false }
154
+ let map = state.toMap()
155
+ store.set("glasses", "audioSetup", map)
156
+ Bridge.sendTypedMessage("audio_setup_changed", body: ["state": map])
157
+ return true
158
+ }
159
+
160
+ /// Glasses without a driver-specific audio rule report `not_applicable` while ready and
161
+ /// `idle` otherwise. Runs before readiness is stored, so the update that marks the glasses
162
+ /// ready already carries the matching `audioSetup`.
163
+ private func publishModelDefaultAudioSetup(_ category: String, _ key: String, _ value: Any) {
164
+ guard ObservableStore.normalizeCategory(category) == "glasses", key == "fullyBooted",
165
+ let ready = value as? Bool,
166
+ DeviceManager.shared.sgc?.publishesAudioSetup != true
167
+ else { return }
168
+ publishAudioSetup(.modelDefault(ready: ready))
169
+ }
170
+
147
171
  /// Apply changes with side effects
148
172
  func apply(_ category: String, _ key: String, _ value: Any) {
149
173
  let oldValue = store.get(category, key)
150
174
  let storeWouldSkipSet = store.wouldSkipSet(category, key, value)
175
+ if !storeWouldSkipSet {
176
+ publishModelDefaultAudioSetup(category, key, value)
177
+ }
151
178
  store.set(category, key, value)
152
179
  if storeWouldSkipSet {
153
180
  return
@@ -2,7 +2,8 @@ import Foundation
2
2
 
3
3
  /// Generated from /changelogs. Do not edit directly.
4
4
  let generatedReleaseChangelogs: [ReleaseChangelog] = [
5
- ReleaseChangelog(version: "3.3.0", markdown: "This release is under active development. User-facing changes will be documented as they land."),
5
+ ReleaseChangelog(version: "3.4.0", markdown: "This release is under active development. User-facing changes will be documented as they land."),
6
+ ReleaseChangelog(version: "3.3.0", markdown: "- **Mentra Call:** Now available on iPhone, with a redesigned call screen and photo sharing during calls.\n- **Microphone:** Improved glasses microphone reliability, including after phone calls.\n- **Photos and gallery:** More reliable photo capture and gallery syncing.\n- **Glasses updates:** More reliable glasses updates, with clearer progress.\n- **Miniapps:** Miniapps now update automatically. Fixed miniapps getting stuck on loading screens.\n- **Mentra AI:** Reliability improvements and bug fixes.\n- **Notes:** Take photos with the glasses camera button, and add meeting and location details to your notes.\n- **Pairing and connections:** Improved glasses audio reconnection on Android.\n- **G1 and NIMO:** Improved text display, including accented letters.\n- **Android tablets:** The Mentra App now rotates to landscape."),
6
7
  ReleaseChangelog(version: "3.2.1", markdown: "- **Livestreamer:** \"Stream Here\" now works without a Wi-Fi network. Improved stream startup and connection reliability.\n- **Photos and gallery:** More reliable photo capture and gallery syncing.\n- **Mentra AI:** Reliability improvements and bug fixes.\n- **Miniapps:** Smoother transitions, with back buttons and gestures that take you to the previous screen inside a miniapp.\n- **Pairing and connections:** Improved G1 pairing and G2 background reconnection.\n- **Glasses updates:** Fixed repeated update checks and improved recovery after interrupted updates.\n- **Mentra Maps:** Bug fixes.\n- **NIMO:** Improved text and map layouts.\n- **Self-hosting:** Connect the Mentra App to your own self-hosted Mentra backend."),
7
8
  ReleaseChangelog(version: "3.2.0", markdown: "- Improved glasses connectivity and Wi-Fi setup.\n\n- Breaking Bluetooth SDK change: `forgetWifiNetwork(ssid)` now returns `WifiForgetResult` instead of `WifiStatusChangeEvent`. Migrate status-only consumers to the semantic `outcome`; the requested network remains `ssid`, while optional post-command connectivity is reported by `connected`, `currentSsid`, and `localIp`."),
8
9
  ReleaseChangelog(version: "3.1.1", markdown: "- Improved Google login on iOS.\n- Pairing no longer requires phone microphone access."),
@@ -2,10 +2,10 @@ import Foundation
2
2
 
3
3
  /// Generated by release CI. Do not edit in a release checkout.
4
4
  enum GeneratedReleaseMetadata {
5
- static let familyBaseVersion = "3.3.0"
6
- static let releaseIdentity = "3.3.0-dev.944"
7
- static let releaseSetId = "mentra-3.3.0-dev.944"
8
- static let sourceCommit = "77b4e08cc991d8d88db9401a5a0157ed647c5c7f"
9
- static let otaManifestUrl = "https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.3.0/mentra-live-ota-3.3.0-dev.944.json"
10
- static let otaManifestSha256 = "faa9e0d6e501772a9ca0e8fd6cdd03d795b5e40c6a1b103b0f0bb4b6d970dd07"
5
+ static let familyBaseVersion = "3.4.0"
6
+ static let releaseIdentity = "3.4.0-beta.1237"
7
+ static let releaseSetId = "mentra-3.4.0-beta.1237"
8
+ static let sourceCommit = "ad9203eb7fe636f5a6a77510451d0a8da34b880c"
9
+ static let otaManifestUrl = "https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.4.0/mentra-live-ota-3.4.0-beta.1237.json"
10
+ static let otaManifestSha256 = "57f73cac781224161574b4a862c6fb76f98aafd384876ef1b06f998797d5e67f"
11
11
  }
@@ -308,6 +308,8 @@ public final class MentraBluetoothSDK {
308
308
  /// instead of throwing `request_in_flight` and refusing the next join.
309
309
  private var hotspotTail: Task<HotspotStatusEvent, Error>?
310
310
  private var pendingVersionInfo: PendingVersionInfoRequest?
311
+ private let besCrashReports = BesCrashReportWaiters()
312
+ private static let besCrashReportedTimeoutMs = 10000
311
313
  private let wifiSessionCapabilities = WifiSessionCapabilities()
312
314
  private var configuredOtaVersionUrl: String?
313
315
 
@@ -540,6 +542,7 @@ public final class MentraBluetoothSDK {
540
542
  let isController = ControllerTypes.ALL.contains(device.model.deviceType)
541
543
  if !isController {
542
544
  requiresAncsForBluetoothRestore = options.requiresAncs
545
+ MentraLive.enableTransportBridging = options.enableTransportBridging
543
546
  }
544
547
  if options.cancelExistingConnectionAttempt {
545
548
  if isController {
@@ -548,6 +551,9 @@ public final class MentraBluetoothSDK {
548
551
  cancelConnectionAttempt()
549
552
  }
550
553
  }
554
+ if !isController {
555
+ MentraLive.clearStaleIosBondPrompt()
556
+ }
551
557
  if options.saveAsDefault && !isController {
552
558
  setDefaultDevice(device)
553
559
  } else if !isController {
@@ -566,6 +572,7 @@ public final class MentraBluetoothSDK {
566
572
  public func connectDefault(options: ConnectOptions = ConnectOptions()) throws {
567
573
  clearBluetoothRestoreIntent()
568
574
  requiresAncsForBluetoothRestore = options.requiresAncs
575
+ MentraLive.enableTransportBridging = options.enableTransportBridging
569
576
  guard let device = currentDefaultDevice() else {
570
577
  throw BluetoothSdkError(
571
578
  code: "default_device_missing",
@@ -704,6 +711,17 @@ public final class MentraBluetoothSDK {
704
711
  )
705
712
  }
706
713
 
714
+ /// Disable a stock action while retaining touch events. Reset by BES on BLE disconnect.
715
+ public func setTouchGestureDefaultBehaviorEnabled(_ gesture: TouchGesture, enabled: Bool) async throws -> SettingsAckEvent {
716
+ try await performSettingsCommand(
717
+ setting: "touch_gesture_default",
718
+ updateStore: { _ in },
719
+ send: { requestId in
720
+ try DeviceManager.shared.sendTouchGestureDefaultBehaviorEnabled(requestId: requestId, gesture: gesture, enabled: enabled)
721
+ }
722
+ )
723
+ }
724
+
707
725
  public func setGalleryModeEnabled(_ enabled: Bool) async throws -> SettingsAckEvent {
708
726
  try await performSettingsCommand(
709
727
  setting: "gallery_mode",
@@ -1174,8 +1192,12 @@ public final class MentraBluetoothSDK {
1174
1192
  /// Fire-and-forget Mentra Live Wi-Fi ADB toggle. Glasses do not ack this
1175
1193
  /// command, so there is no pending-response wait (unlike hotspot / Wi-Fi forget).
1176
1194
  public func setWifiAdbState(enabled: Bool) async throws {
1195
+ try await setWifiAdbState(enabled: enabled, expectedBluetoothMac: nil)
1196
+ }
1197
+
1198
+ public func setWifiAdbState(enabled: Bool, expectedBluetoothMac: String?) async throws {
1177
1199
  try requireGlassesConnected(operation: "toggle Wi-Fi ADB")
1178
- DeviceManager.shared.setWifiAdbState(enabled)
1200
+ try DeviceManager.shared.setWifiAdbState(enabled, expectedBluetoothMac: expectedBluetoothMac)
1179
1201
  }
1180
1202
 
1181
1203
  func setSystemTime(timestampMs: Int64) {
@@ -1769,6 +1791,18 @@ public final class MentraBluetoothSDK {
1769
1791
  try DeviceManager.shared.sendIncidentId(incidentId, apiBaseUrl: apiBaseUrl)
1770
1792
  }
1771
1793
 
1794
+ /// Resolves on the glasses' matching `ok:true` ack; throws on `ok:false`, disconnect or timeout.
1795
+ func sendBesCrashReported(incidentKey: String, reportId: String) async throws {
1796
+ try requireGlassesConnected(operation: "report the BES crash")
1797
+ try await besCrashReports.report(
1798
+ incidentKey: incidentKey,
1799
+ reportId: reportId,
1800
+ timeoutMs: Self.besCrashReportedTimeoutMs
1801
+ ) {
1802
+ try DeviceManager.shared.sendBesCrashReported(incidentKey: incidentKey, reportId: reportId)
1803
+ }
1804
+ }
1805
+
1772
1806
  public func invalidate() {
1773
1807
  resetWifiProtocolSession(sessionId: "", code: "sdk_closed")
1774
1808
  if let bluetoothAvailabilityListenerId {
@@ -2447,6 +2481,10 @@ public final class MentraBluetoothSDK {
2447
2481
  case "glasses":
2448
2482
  if changes["connected"] as? Bool == false {
2449
2483
  resetWifiProtocolSession(sessionId: "", code: "wifi_session_disconnected")
2484
+ besCrashReports.rejectAll(BluetoothSdkError(
2485
+ code: "glasses_not_connected",
2486
+ message: "Glasses disconnected before acknowledging bes_crash_reported."
2487
+ ))
2450
2488
  }
2451
2489
  // CBCentralManager state is read here on the main actor, not on the analytics queue.
2452
2490
  let phoneBluetoothOff = BluetoothAvailability.shared.isPoweredOff
@@ -2694,9 +2732,9 @@ public final class MentraBluetoothSDK {
2694
2732
  let event = GalleryStatusEvent(values: data)
2695
2733
  pendingGalleryStatus?.resolve(event)
2696
2734
  delegate?.mentraBluetoothSDK(self, didReceive: .raw(name: "gallery_status", values: event.values))
2697
- case "pairing_info":
2698
- delegate?.mentraBluetoothSDK(self, didReceive: .raw(name: "pairing_info", values: data))
2699
- case "entering_pairing_mode", "owner_replaced":
2735
+ case "pairing_info", "pairing_state_changed", "audio_setup_changed":
2736
+ delegate?.mentraBluetoothSDK(self, didReceive: .raw(name: eventName, values: data))
2737
+ case "entering_pairing_mode", "pairing_mode_ended", "owner_replaced":
2700
2738
  delegate?.mentraBluetoothSDK(self, didReceive: .raw(name: eventName, values: data))
2701
2739
  case "photo_response":
2702
2740
  let event = PhotoResponseEvent(values: data)
@@ -2774,6 +2812,13 @@ public final class MentraBluetoothSDK {
2774
2812
  }
2775
2813
  }
2776
2814
  delegate?.mentraBluetoothSDK(self, didReceive: .otaStatus(event))
2815
+ case "bes_crash_detected":
2816
+ var values = data
2817
+ values["type"] = "bes_crash_detected"
2818
+ delegate?.mentraBluetoothSDK(self, didReceive: .besCrashDetected(BesCrashDetectedEvent(values: values)))
2819
+ case "bes_crash_reported_ack":
2820
+ // Request-scoped: consumed by the waiting sendBesCrashReported call, never a delegate event.
2821
+ besCrashReports.onAck(data)
2777
2822
  case "settings_ack":
2778
2823
  let event = SettingsAckEvent(values: data)
2779
2824
  handleSettingsAckForRequests(event)
@@ -2792,7 +2837,8 @@ public final class MentraBluetoothSDK {
2792
2837
  self,
2793
2838
  didFail: BluetoothSdkError(
2794
2839
  code: "pair_failure",
2795
- message: data["error"] as? String ?? data.description
2840
+ message: data["error"] as? String ?? data.description,
2841
+ failureCode: data["code"] as? String
2796
2842
  )
2797
2843
  )
2798
2844
  default:
@@ -0,0 +1,13 @@
1
+ import Foundation
2
+
3
+ /// Mentra Live touchpad gestures, using the public touch_event names.
4
+ public enum TouchGesture: String, CaseIterable, Sendable {
5
+ case singleTap = "single_tap"
6
+ case doubleTap = "double_tap"
7
+ case tripleTap = "triple_tap"
8
+ case longPress = "long_press"
9
+ case forwardSwipe = "forward_swipe"
10
+ case backwardSwipe = "backward_swipe"
11
+ case upSwipe = "up_swipe"
12
+ case downSwipe = "down_swipe"
13
+ }