@mentra/bluetooth-sdk 3.3.0 → 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 (168) hide show
  1. package/MIGRATION.md +61 -0
  2. package/README.md +80 -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 +85 -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 +154 -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 +1 -0
  13. package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedReleaseMetadata.kt +6 -6
  14. package/android/src/main/java/com/mentra/bluetoothsdk/MentraBluetoothSdk.kt +27 -2
  15. package/android/src/main/java/com/mentra/bluetoothsdk/connection/ConnectionModels.kt +5 -0
  16. package/android/src/main/java/com/mentra/bluetoothsdk/events/BluetoothEvents.kt +16 -0
  17. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/GlassesAudioSetupPolicy.kt +64 -0
  18. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLive.kt +925 -155
  19. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLiveOwnerLossPolicy.kt +227 -0
  20. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingAdvertisement.kt +19 -0
  21. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingReadinessPolicy.kt +94 -0
  22. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingStateMachine.kt +411 -0
  23. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingStateStore.kt +124 -0
  24. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/Nimo.kt +54 -59
  25. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasCoordinator.kt +5 -32
  26. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasEncoder.kt +8 -1
  27. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasSession.kt +3 -10
  28. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/SGCManager.kt +6 -0
  29. package/android/src/main/java/com/mentra/bluetoothsdk/status/DeviceStatus.kt +50 -0
  30. package/android/src/main/java/com/mentra/bluetoothsdk/stt/BoundedAudioQueue.kt +92 -0
  31. package/android/src/main/java/com/mentra/bluetoothsdk/stt/OnDeviceRecognizerHost.kt +169 -0
  32. package/android/src/main/java/com/mentra/bluetoothsdk/stt/STTTools.kt +74 -115
  33. package/android/src/main/java/com/mentra/bluetoothsdk/stt/SherpaOnnxTranscriber.kt +348 -357
  34. package/android/src/main/java/com/mentra/bluetoothsdk/stt/SpeechActivityDetector.kt +211 -0
  35. package/android/src/main/java/com/mentra/bluetoothsdk/stt/SpeechActivityEngine.kt +137 -0
  36. package/android/src/main/java/com/mentra/bluetoothsdk/stt/SttTextFormatter.kt +52 -0
  37. package/android/src/main/java/com/mentra/bluetoothsdk/stt/WakeWordDetector.kt +235 -0
  38. package/android/src/main/java/com/mentra/bluetoothsdk/utils/AvifExifStripper.java +2 -2
  39. package/android/src/main/java/com/mentra/bluetoothsdk/utils/BlePhotoUploadService.java +3 -3
  40. package/android/src/main/java/com/mentra/bluetoothsdk/utils/IncidentLogBleRelayNaming.java +11 -0
  41. package/android/src/main/java/com/mentra/bluetoothsdk/utils/audio/AudioRouteWatcher.kt +120 -0
  42. package/android/src/main/java/com/mentra/bluetoothsdk/utils/audio/PcmStreamPlayer.kt +181 -16
  43. package/android/src/main/java/com/mentra/bluetoothsdk/utils/audio/PcmUrlPlayback.kt +177 -0
  44. package/android/src/test/java/com/mentra/bluetoothsdk/BesCrashReportWaitersTest.kt +112 -0
  45. package/android/src/test/java/com/mentra/bluetoothsdk/DeviceManagerOwnerLossTest.kt +146 -0
  46. package/android/src/test/java/com/mentra/bluetoothsdk/GlassesStatusAudioSetupTest.kt +51 -0
  47. package/android/src/test/java/com/mentra/bluetoothsdk/GlassesStatusClassicAudioTest.kt +2 -0
  48. package/android/src/test/java/com/mentra/bluetoothsdk/WifiAdbPeerIntentTest.kt +19 -0
  49. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/GlassesAudioSetupPolicyTest.kt +65 -0
  50. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveAudioSetupReadinessTest.kt +231 -0
  51. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveGlassesReadyBurstTest.kt +5 -1
  52. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveIncidentDispatchTest.kt +183 -0
  53. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveOwnerLossPolicyTest.kt +368 -0
  54. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingAdvertisementParserTest.kt +20 -0
  55. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingReadinessPolicyTest.kt +136 -0
  56. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLivePairingStateMachineTest.kt +346 -0
  57. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasCoordinatorTest.kt +1 -56
  58. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasSessionTest.kt +0 -22
  59. package/android/src/test/java/com/mentra/bluetoothsdk/utils/IncidentLogBleRelayNamingTest.kt +23 -0
  60. package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/BoundedAudioQueueTest.kt +81 -0
  61. package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/OnDeviceRecognizerHostTest.kt +216 -0
  62. package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/STTToolsExtractionTest.kt +108 -0
  63. package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/SpeechActivityDetectorTest.kt +126 -0
  64. package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/SpeechActivityEngineTest.kt +245 -0
  65. package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/SttTextFormatterTest.kt +67 -0
  66. package/android/src/testDebug/java/com/mentra/bluetoothsdk/utils/audio/PcmUrlPlaybackTest.kt +76 -0
  67. package/build/BluetoothSdk.types.d.ts +201 -1
  68. package/build/BluetoothSdk.types.d.ts.map +1 -1
  69. package/build/BluetoothSdk.types.js.map +1 -1
  70. package/build/_private/BluetoothSdkModule.d.ts +43 -5
  71. package/build/_private/BluetoothSdkModule.d.ts.map +1 -1
  72. package/build/_private/BluetoothSdkModule.js +2 -0
  73. package/build/_private/BluetoothSdkModule.js.map +1 -1
  74. package/build/generated/changelogCatalog.d.ts +3 -0
  75. package/build/generated/changelogCatalog.d.ts.map +1 -1
  76. package/build/generated/changelogCatalog.js +4 -0
  77. package/build/generated/changelogCatalog.js.map +1 -1
  78. package/build/generated/releaseMetadata.js +6 -6
  79. package/build/generated/releaseMetadata.js.map +1 -1
  80. package/build/index.d.ts +1 -1
  81. package/build/index.d.ts.map +1 -1
  82. package/build/index.js +9 -0
  83. package/build/index.js.map +1 -1
  84. package/ios/BluetoothSdkModule.swift +76 -12
  85. package/ios/MentraBluetoothSDK.podspec +4 -0
  86. package/ios/Packages/SherpaOnnx/SherpaOnnx.swift +23 -5
  87. package/ios/Resources/SileroVad/silero_vad.onnx +0 -0
  88. package/ios/Source/BesCrashReportWaiters.swift +64 -0
  89. package/ios/Source/BluetoothSdkDefaults.swift +2 -2
  90. package/ios/Source/Bridge.swift +11 -3
  91. package/ios/Source/DeviceManager.swift +131 -18
  92. package/ios/Source/DeviceStore.swift +27 -0
  93. package/ios/Source/GeneratedChangelogCatalog.swift +1 -0
  94. package/ios/Source/GeneratedReleaseMetadata.swift +6 -6
  95. package/ios/Source/MentraBluetoothSDK.swift +40 -5
  96. package/ios/Source/audio/PcmStreamPlayer.swift +290 -57
  97. package/ios/Source/audio/PcmUrlPlayback.swift +231 -0
  98. package/ios/Source/audio/SpeechActivity.swift +277 -0
  99. package/ios/Source/errors/BluetoothSdkError.swift +5 -1
  100. package/ios/Source/events/BluetoothEvents.swift +41 -0
  101. package/ios/Source/internal/BleTraceLogger.swift +9 -6
  102. package/ios/Source/internal/BluetoothAvailability.swift +15 -5
  103. package/ios/Source/sgcs/GlassesAudioSetupPolicy.swift +186 -0
  104. package/ios/Source/sgcs/MentraLive.swift +1270 -189
  105. package/ios/Source/sgcs/MentraLivePairingAdvertisement.swift +260 -1
  106. package/ios/Source/sgcs/MentraLivePairingStateMachine.swift +385 -0
  107. package/ios/Source/sgcs/MentraLivePairingStateStore.swift +121 -0
  108. package/ios/Source/sgcs/Nimo.swift +10 -3
  109. package/ios/Source/sgcs/NimoCanvasCoordinator.swift +39 -9
  110. package/ios/Source/sgcs/SGCManager.swift +13 -0
  111. package/ios/Source/sgcs/Simulated.swift +2 -0
  112. package/ios/Source/status/DeviceStatus.swift +35 -0
  113. package/ios/Source/stt/STTTools.swift +13 -31
  114. package/ios/Source/stt/SherpaOnnxTranscriber.swift +204 -162
  115. package/ios/Source/stt/SileroSpeechActivity.swift +87 -0
  116. package/ios/Source/stt/WakeWordDetector.swift +145 -0
  117. package/ios/Source/types/DeviceModels.swift +8 -1
  118. package/ios/Source/utils/AudioSessionMonitor.swift +158 -5
  119. package/ios/Source/utils/BoundedWait.swift +44 -0
  120. package/ios/Source/utils/DemandDrivenAudioWorker.swift +79 -0
  121. package/ios/Source/utils/SttModelTraits.swift +62 -0
  122. package/ios/Tests/BesCrashReportTests.swift +142 -0
  123. package/ios/Tests/BluetoothAudioRouteTests.swift +82 -0
  124. package/ios/Tests/DemandDrivenAudioWorkerTests.swift +171 -0
  125. package/ios/Tests/DeviceManagerReconnectTests.swift +4 -2
  126. package/ios/Tests/GlassesAudioSetupPolicyTests.swift +197 -0
  127. package/ios/Tests/IncidentLogDispatchTests.swift +158 -0
  128. package/ios/Tests/MentraLiveAudioSetupTests.swift +209 -0
  129. package/ios/Tests/MentraLiveConnectionOptionsTests.swift +55 -0
  130. package/ios/Tests/MentraLivePairingAdvertisementTests.swift +327 -0
  131. package/ios/Tests/MentraLivePairingStateMachineTests.swift +402 -0
  132. package/ios/Tests/MentraLiveSessionReadinessTests.swift +368 -26
  133. package/ios/Tests/NimoCanvasTransportTests.swift +58 -0
  134. package/ios/Tests/PcmStreamTests.swift +299 -0
  135. package/ios/Tests/SpeechActivityTests.swift +238 -0
  136. package/ios/Tests/SttModelTraitsTests.swift +62 -0
  137. package/ios/Tests/WifiAdbDispatchTests.swift +118 -0
  138. package/package.json +3 -2
  139. package/plugin/build/withAndroid.js +9 -11
  140. package/plugin/build/withKotlinVersion.d.ts +2 -0
  141. package/plugin/build/withKotlinVersion.js +46 -0
  142. package/src/BluetoothSdk.types.ts +201 -1
  143. package/src/_private/BluetoothSdkModule.ts +47 -5
  144. package/src/generated/changelogCatalog.ts +4 -0
  145. package/src/generated/releaseMetadata.ts +6 -6
  146. package/src/index.ts +22 -0
  147. package/android/silero/LICENSE.md +0 -17
  148. package/android/silero/build.gradle +0 -50
  149. package/android/silero/proguard-rules.pro +0 -24
  150. package/android/silero/src/androidTest/assets/hello.wav +0 -0
  151. package/android/silero/src/androidTest/java/com/konovalov/vad/silero/VadSileroTest.kt +0 -79
  152. package/android/silero/src/main/java/com/konovalov/vad/silero/Vad.kt +0 -160
  153. package/android/silero/src/main/java/com/konovalov/vad/silero/VadSilero.kt +0 -449
  154. package/android/silero/src/main/java/com/konovalov/vad/silero/config/FrameSize.kt +0 -15
  155. package/android/silero/src/main/java/com/konovalov/vad/silero/config/Mode.kt +0 -14
  156. package/android/silero/src/main/java/com/konovalov/vad/silero/config/SampleRate.kt +0 -12
  157. package/android/silero/src/main/java/com/konovalov/vad/silero/utils/AudioUtils.kt +0 -47
  158. package/android/silero/src/main/java/com/konovalov/vad/silero/utils/TensorMap.kt +0 -41
  159. package/android/silero/src/test/java/com/konovalov/vad/silero/utils/AudioUtilsTest.kt +0 -44
  160. package/android/src/debug/java/com/mentra/bluetoothsdk/sgcs/NimoDiagnostics.kt +0 -368
  161. package/android/src/debug/java/com/mentra/bluetoothsdk/sgcs/NimoFramebufferProtocol.kt +0 -156
  162. package/android/src/main/java/com/mentra/bluetoothsdk/stt/VadGateSpeechPolicy.kt +0 -229
  163. package/android/src/release/java/com/mentra/bluetoothsdk/sgcs/NimoDiagnostics.kt +0 -20
  164. package/android/src/testDebug/java/com/mentra/bluetoothsdk/sgcs/NimoDiagnosticsTest.kt +0 -287
  165. package/android/src/testDebug/java/com/mentra/bluetoothsdk/sgcs/NimoFramebufferProtocolTest.kt +0 -127
  166. package/android/src/testDebug/java/com/mentra/bluetoothsdk/sgcs/NimoLifecycleTest.kt +0 -288
  167. /package/android/{silero/src/main/assets/LICENSE → src/main/assets/vad/LICENSE.silero_vad} +0 -0
  168. /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 {
967
1010
  #if !os(macOS) && (!SWIFT_PACKAGE || MENTRA_FEATURE_LOCAL_STT)
968
- Bridge.log("MAN: Restarting SherpaOnnxTranscriber via command")
969
- transcriber.restart()
1011
+ return transcriber.isModelLoaded(path)
970
1012
  #else
971
- Bridge.log("MAN: Local STT is not included in this SwiftPM build")
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 {
1020
+ #if !os(macOS) && (!SWIFT_PACKAGE || MENTRA_FEATURE_LOCAL_STT)
1021
+ Bridge.log("MAN: Restarting SherpaOnnxTranscriber via command")
1022
+ return await transcriber.restart()
1023
+ #else
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)
@@ -1865,9 +1944,18 @@ struct ViewState {
1865
1944
  }
1866
1945
  initSGC(defaultWearable)
1867
1946
  (sgc as? MentraLive)?.setRequiresAncs(requiresAncs)
1868
- if let live = sgc as? MentraLive, live.isPairingYieldActive() {
1869
- Bridge.log("MAN: connectDefault skipped — Mentra Live pairing yield active")
1870
- 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
+ }
1871
1959
  }
1872
1960
  searching = true
1873
1961
  sgc?.connectById(reconnectTarget)
@@ -1889,21 +1977,21 @@ struct ViewState {
1889
1977
  }
1890
1978
 
1891
1979
  func connectByName(_ dName: String, requiresAncs: Bool = true) {
1892
- Bridge.log("MAN: Connecting to wearable: \(dName)")
1893
1980
  var name = dName
1894
1981
 
1895
1982
  // use stored device name if available:
1896
1983
  if dName.isEmpty && !deviceName.isEmpty {
1897
1984
  name = deviceName
1898
1985
  }
1986
+ Bridge.log("PAIRFLOW: connect_by_name requested=\(dName) resolved=\(name)")
1899
1987
 
1900
1988
  if pendingWearable.isEmpty, defaultWearable.isEmpty {
1901
- Bridge.log("MAN: No pending or default wearable, returning")
1989
+ Bridge.log("PAIRFLOW: connect_by_name abort reason=no_wearable")
1902
1990
  return
1903
1991
  }
1904
1992
 
1905
1993
  if pendingWearable.isEmpty, !defaultWearable.isEmpty {
1906
- Bridge.log("MAN: No pending wearable, using default wearable: \(defaultWearable)")
1994
+ Bridge.log("PAIRFLOW: connect_by_name pending=\(defaultWearable)")
1907
1995
  pendingWearable = defaultWearable
1908
1996
  }
1909
1997
 
@@ -1914,6 +2002,21 @@ struct ViewState {
1914
2002
  return
1915
2003
  }
1916
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)")
1917
2020
  Task {
1918
2021
  disconnect(clearPendingConnection: false)
1919
2022
  try? await Task.sleep(nanoseconds: 100 * 1_000_000) // 100ms
@@ -1954,6 +2057,8 @@ struct ViewState {
1954
2057
  #if os(macOS)
1955
2058
  audioRouteObserver = nil
1956
2059
  glassesBluetoothClassicConnected = false
2060
+ glassesBluetoothClassicProfilesConnected = false
2061
+ glassesBluetoothAudioRouted = false
1957
2062
  otherBtConnected = false
1958
2063
  #endif
1959
2064
  sgc?.clearDisplay() // clear the screen
@@ -2030,6 +2135,14 @@ struct ViewState {
2030
2135
 
2031
2136
  func forget() {
2032
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
+ }
2033
2146
  // Call forget first to stop timers/handlers/reconnect logic
2034
2147
  sgc?.forget()
2035
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,6 +2,7 @@ import Foundation
2
2
 
3
3
  /// Generated from /changelogs. Do not edit directly.
4
4
  let generatedReleaseChangelogs: [ReleaseChangelog] = [
5
+ ReleaseChangelog(version: "3.4.0", markdown: "This release is under active development. User-facing changes will be documented as they land."),
5
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`."),
@@ -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"
7
- static let releaseSetId = "mentra-3.3.0"
8
- static let sourceCommit = "5bd50400b076b758691429755b6e1bd7b77268fb"
9
- static let otaManifestUrl = "https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.3.0/mentra-live-ota-3.3.0-beta.1188.json"
10
- static let otaManifestSha256 = "66070872d18ee11303347e1be71b7385af96aab30adc3d226ceb4a82c2c4848f"
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",
@@ -1185,8 +1192,12 @@ public final class MentraBluetoothSDK {
1185
1192
  /// Fire-and-forget Mentra Live Wi-Fi ADB toggle. Glasses do not ack this
1186
1193
  /// command, so there is no pending-response wait (unlike hotspot / Wi-Fi forget).
1187
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 {
1188
1199
  try requireGlassesConnected(operation: "toggle Wi-Fi ADB")
1189
- DeviceManager.shared.setWifiAdbState(enabled)
1200
+ try DeviceManager.shared.setWifiAdbState(enabled, expectedBluetoothMac: expectedBluetoothMac)
1190
1201
  }
1191
1202
 
1192
1203
  func setSystemTime(timestampMs: Int64) {
@@ -1780,6 +1791,18 @@ public final class MentraBluetoothSDK {
1780
1791
  try DeviceManager.shared.sendIncidentId(incidentId, apiBaseUrl: apiBaseUrl)
1781
1792
  }
1782
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
+
1783
1806
  public func invalidate() {
1784
1807
  resetWifiProtocolSession(sessionId: "", code: "sdk_closed")
1785
1808
  if let bluetoothAvailabilityListenerId {
@@ -2458,6 +2481,10 @@ public final class MentraBluetoothSDK {
2458
2481
  case "glasses":
2459
2482
  if changes["connected"] as? Bool == false {
2460
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
+ ))
2461
2488
  }
2462
2489
  // CBCentralManager state is read here on the main actor, not on the analytics queue.
2463
2490
  let phoneBluetoothOff = BluetoothAvailability.shared.isPoweredOff
@@ -2705,9 +2732,9 @@ public final class MentraBluetoothSDK {
2705
2732
  let event = GalleryStatusEvent(values: data)
2706
2733
  pendingGalleryStatus?.resolve(event)
2707
2734
  delegate?.mentraBluetoothSDK(self, didReceive: .raw(name: "gallery_status", values: event.values))
2708
- case "pairing_info":
2709
- delegate?.mentraBluetoothSDK(self, didReceive: .raw(name: "pairing_info", values: data))
2710
- 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":
2711
2738
  delegate?.mentraBluetoothSDK(self, didReceive: .raw(name: eventName, values: data))
2712
2739
  case "photo_response":
2713
2740
  let event = PhotoResponseEvent(values: data)
@@ -2785,6 +2812,13 @@ public final class MentraBluetoothSDK {
2785
2812
  }
2786
2813
  }
2787
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)
2788
2822
  case "settings_ack":
2789
2823
  let event = SettingsAckEvent(values: data)
2790
2824
  handleSettingsAckForRequests(event)
@@ -2803,7 +2837,8 @@ public final class MentraBluetoothSDK {
2803
2837
  self,
2804
2838
  didFail: BluetoothSdkError(
2805
2839
  code: "pair_failure",
2806
- message: data["error"] as? String ?? data.description
2840
+ message: data["error"] as? String ?? data.description,
2841
+ failureCode: data["code"] as? String
2807
2842
  )
2808
2843
  )
2809
2844
  default: