@mentra/engine 0.1.0-beta.0
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 +79 -0
- package/build/devtools.d.ts +11 -0
- package/build/devtools.d.ts.map +1 -0
- package/build/devtools.js +13 -0
- package/build/devtools.js.map +1 -0
- package/build/engine.d.ts +261 -0
- package/build/engine.d.ts.map +1 -0
- package/build/engine.js +170 -0
- package/build/engine.js.map +1 -0
- package/build/facades/dev.d.ts +58 -0
- package/build/facades/dev.d.ts.map +1 -0
- package/build/facades/dev.js +189 -0
- package/build/facades/dev.js.map +1 -0
- package/build/facades/display.d.ts +21 -0
- package/build/facades/display.d.ts.map +1 -0
- package/build/facades/display.js +17 -0
- package/build/facades/display.js.map +1 -0
- package/build/facades/displayMirror.d.ts +15 -0
- package/build/facades/displayMirror.d.ts.map +1 -0
- package/build/facades/displayMirror.js +29 -0
- package/build/facades/displayMirror.js.map +1 -0
- package/build/facades/gallery.d.ts +62 -0
- package/build/facades/gallery.d.ts.map +1 -0
- package/build/facades/gallery.js +61 -0
- package/build/facades/gallery.js.map +1 -0
- package/build/facades/glasses.d.ts +141 -0
- package/build/facades/glasses.d.ts.map +1 -0
- package/build/facades/glasses.js +199 -0
- package/build/facades/glasses.js.map +1 -0
- package/build/facades/glassesSettings.d.ts +13 -0
- package/build/facades/glassesSettings.d.ts.map +1 -0
- package/build/facades/glassesSettings.js +54 -0
- package/build/facades/glassesSettings.js.map +1 -0
- package/build/facades/glassesWifi.d.ts +25 -0
- package/build/facades/glassesWifi.d.ts.map +1 -0
- package/build/facades/glassesWifi.js +57 -0
- package/build/facades/glassesWifi.js.map +1 -0
- package/build/facades/miniapps.d.ts +43 -0
- package/build/facades/miniapps.d.ts.map +1 -0
- package/build/facades/miniapps.js +49 -0
- package/build/facades/miniapps.js.map +1 -0
- package/build/facades/notifications.d.ts +13 -0
- package/build/facades/notifications.d.ts.map +1 -0
- package/build/facades/notifications.js +12 -0
- package/build/facades/notifications.js.map +1 -0
- package/build/facades/ota.d.ts +103 -0
- package/build/facades/ota.d.ts.map +1 -0
- package/build/facades/ota.js +156 -0
- package/build/facades/ota.js.map +1 -0
- package/build/facades/pairing.d.ts +114 -0
- package/build/facades/pairing.d.ts.map +1 -0
- package/build/facades/pairing.js +275 -0
- package/build/facades/pairing.js.map +1 -0
- package/build/facades/permissions.d.ts +33 -0
- package/build/facades/permissions.d.ts.map +1 -0
- package/build/facades/permissions.js +155 -0
- package/build/facades/permissions.js.map +1 -0
- package/build/facades/phoneNotifications.d.ts +21 -0
- package/build/facades/phoneNotifications.d.ts.map +1 -0
- package/build/facades/phoneNotifications.js +51 -0
- package/build/facades/phoneNotifications.js.map +1 -0
- package/build/facades/reports.d.ts +36 -0
- package/build/facades/reports.d.ts.map +1 -0
- package/build/facades/reports.js +134 -0
- package/build/facades/reports.js.map +1 -0
- package/build/facades/session.d.ts +21 -0
- package/build/facades/session.d.ts.map +1 -0
- package/build/facades/session.js +52 -0
- package/build/facades/session.js.map +1 -0
- package/build/facades/settings.d.ts +37 -0
- package/build/facades/settings.d.ts.map +1 -0
- package/build/facades/settings.js +55 -0
- package/build/facades/settings.js.map +1 -0
- package/build/facades/speech.d.ts +30 -0
- package/build/facades/speech.d.ts.map +1 -0
- package/build/facades/speech.js +37 -0
- package/build/facades/speech.js.map +1 -0
- package/build/index.d.ts +43 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +45 -0
- package/build/index.js.map +1 -0
- package/build/internal.d.ts +67 -0
- package/build/internal.d.ts.map +1 -0
- package/build/internal.js +90 -0
- package/build/internal.js.map +1 -0
- package/build/runtime/bootstrap.d.ts +83 -0
- package/build/runtime/bootstrap.d.ts.map +1 -0
- package/build/runtime/bootstrap.js +56 -0
- package/build/runtime/bootstrap.js.map +1 -0
- package/build/runtime/config.d.ts +146 -0
- package/build/runtime/config.d.ts.map +1 -0
- package/build/runtime/config.js +18 -0
- package/build/runtime/config.js.map +1 -0
- package/build/runtime/streamConfig.d.ts +4 -0
- package/build/runtime/streamConfig.d.ts.map +1 -0
- package/build/runtime/streamConfig.js +38 -0
- package/build/runtime/streamConfig.js.map +1 -0
- package/build/services/AppRegistry.d.ts +269 -0
- package/build/services/AppRegistry.d.ts.map +1 -0
- package/build/services/AppRegistry.js +1079 -0
- package/build/services/AppRegistry.js.map +1 -0
- package/build/services/AudioCloudUplink.d.ts +9 -0
- package/build/services/AudioCloudUplink.d.ts.map +1 -0
- package/build/services/AudioCloudUplink.js +48 -0
- package/build/services/AudioCloudUplink.js.map +1 -0
- package/build/services/AudioPlaybackService.d.ts +175 -0
- package/build/services/AudioPlaybackService.d.ts.map +1 -0
- package/build/services/AudioPlaybackService.js +705 -0
- package/build/services/AudioPlaybackService.js.map +1 -0
- package/build/services/AutomaticReportResult.d.ts +20 -0
- package/build/services/AutomaticReportResult.d.ts.map +1 -0
- package/build/services/AutomaticReportResult.js +29 -0
- package/build/services/AutomaticReportResult.js.map +1 -0
- package/build/services/BlobStore.d.ts +91 -0
- package/build/services/BlobStore.d.ts.map +1 -0
- package/build/services/BlobStore.js +668 -0
- package/build/services/BlobStore.js.map +1 -0
- package/build/services/CaptionsTesterReportService.d.ts +4 -0
- package/build/services/CaptionsTesterReportService.d.ts.map +1 -0
- package/build/services/CaptionsTesterReportService.js +80 -0
- package/build/services/CaptionsTesterReportService.js.map +1 -0
- package/build/services/CloudAudioSubscriptionSync.d.ts +24 -0
- package/build/services/CloudAudioSubscriptionSync.d.ts.map +1 -0
- package/build/services/CloudAudioSubscriptionSync.js +39 -0
- package/build/services/CloudAudioSubscriptionSync.js.map +1 -0
- package/build/services/CloudClientService.d.ts +143 -0
- package/build/services/CloudClientService.d.ts.map +1 -0
- package/build/services/CloudClientService.js +644 -0
- package/build/services/CloudClientService.js.map +1 -0
- package/build/services/CloudTranscriptE2EMetrics.d.ts +4 -0
- package/build/services/CloudTranscriptE2EMetrics.d.ts.map +1 -0
- package/build/services/CloudTranscriptE2EMetrics.js +24 -0
- package/build/services/CloudTranscriptE2EMetrics.js.map +1 -0
- package/build/services/ConnectionCoordinator.d.ts +51 -0
- package/build/services/ConnectionCoordinator.d.ts.map +1 -0
- package/build/services/ConnectionCoordinator.js +34 -0
- package/build/services/ConnectionCoordinator.js.map +1 -0
- package/build/services/DevServerBridge.d.ts +63 -0
- package/build/services/DevServerBridge.d.ts.map +1 -0
- package/build/services/DevServerBridge.js +294 -0
- package/build/services/DevServerBridge.js.map +1 -0
- package/build/services/DeviceEventRouter.d.ts +3 -0
- package/build/services/DeviceEventRouter.d.ts.map +1 -0
- package/build/services/DeviceEventRouter.js +190 -0
- package/build/services/DeviceEventRouter.js.map +1 -0
- package/build/services/DeviceStoreHydration.d.ts +38 -0
- package/build/services/DeviceStoreHydration.d.ts.map +1 -0
- package/build/services/DeviceStoreHydration.js +124 -0
- package/build/services/DeviceStoreHydration.js.map +1 -0
- package/build/services/DisplayProcessor.d.ts +223 -0
- package/build/services/DisplayProcessor.d.ts.map +1 -0
- package/build/services/DisplayProcessor.js +552 -0
- package/build/services/DisplayProcessor.js.map +1 -0
- package/build/services/GlassesReadiness.d.ts +41 -0
- package/build/services/GlassesReadiness.d.ts.map +1 -0
- package/build/services/GlassesReadiness.js +82 -0
- package/build/services/GlassesReadiness.js.map +1 -0
- package/build/services/GlassesSettingsSync.d.ts +33 -0
- package/build/services/GlassesSettingsSync.d.ts.map +1 -0
- package/build/services/GlassesSettingsSync.js +121 -0
- package/build/services/GlassesSettingsSync.js.map +1 -0
- package/build/services/GlassesStatusProjection.d.ts +3 -0
- package/build/services/GlassesStatusProjection.d.ts.map +1 -0
- package/build/services/GlassesStatusProjection.js +65 -0
- package/build/services/GlassesStatusProjection.js.map +1 -0
- package/build/services/HeadingService.d.ts +27 -0
- package/build/services/HeadingService.d.ts.map +1 -0
- package/build/services/HeadingService.js +96 -0
- package/build/services/HeadingService.js.map +1 -0
- package/build/services/LocalDisplayManager.d.ts +139 -0
- package/build/services/LocalDisplayManager.d.ts.map +1 -0
- package/build/services/LocalDisplayManager.js +579 -0
- package/build/services/LocalDisplayManager.js.map +1 -0
- package/build/services/LocalMiniappRuntime.d.ts +439 -0
- package/build/services/LocalMiniappRuntime.d.ts.map +1 -0
- package/build/services/LocalMiniappRuntime.js +3695 -0
- package/build/services/LocalMiniappRuntime.js.map +1 -0
- package/build/services/LocalSttFallbackCoordinator.d.ts +57 -0
- package/build/services/LocalSttFallbackCoordinator.d.ts.map +1 -0
- package/build/services/LocalSttFallbackCoordinator.js +137 -0
- package/build/services/LocalSttFallbackCoordinator.js.map +1 -0
- package/build/services/MentraJSCrashController.d.ts +97 -0
- package/build/services/MentraJSCrashController.d.ts.map +1 -0
- package/build/services/MentraJSCrashController.js +138 -0
- package/build/services/MentraJSCrashController.js.map +1 -0
- package/build/services/MentraJSCrashloopReportService.d.ts +9 -0
- package/build/services/MentraJSCrashloopReportService.d.ts.map +1 -0
- package/build/services/MentraJSCrashloopReportService.js +54 -0
- package/build/services/MentraJSCrashloopReportService.js.map +1 -0
- package/build/services/MentraJSLogPipeline.d.ts +87 -0
- package/build/services/MentraJSLogPipeline.d.ts.map +1 -0
- package/build/services/MentraJSLogPipeline.js +137 -0
- package/build/services/MentraJSLogPipeline.js.map +1 -0
- package/build/services/MentraJSRouter.d.ts +203 -0
- package/build/services/MentraJSRouter.d.ts.map +1 -0
- package/build/services/MentraJSRouter.js +480 -0
- package/build/services/MentraJSRouter.js.map +1 -0
- package/build/services/MentraUIRouter.d.ts +137 -0
- package/build/services/MentraUIRouter.d.ts.map +1 -0
- package/build/services/MentraUIRouter.js +210 -0
- package/build/services/MentraUIRouter.js.map +1 -0
- package/build/services/MicStateCoordinator.d.ts +37 -0
- package/build/services/MicStateCoordinator.d.ts.map +1 -0
- package/build/services/MicStateCoordinator.js +81 -0
- package/build/services/MicStateCoordinator.js.map +1 -0
- package/build/services/MiniappEngine.d.ts +31 -0
- package/build/services/MiniappEngine.d.ts.map +1 -0
- package/build/services/MiniappEngine.js +119 -0
- package/build/services/MiniappEngine.js.map +1 -0
- package/build/services/MiniappLauncher.d.ts +129 -0
- package/build/services/MiniappLauncher.d.ts.map +1 -0
- package/build/services/MiniappLauncher.js +291 -0
- package/build/services/MiniappLauncher.js.map +1 -0
- package/build/services/MiniappRunningRegistry.d.ts +24 -0
- package/build/services/MiniappRunningRegistry.d.ts.map +1 -0
- package/build/services/MiniappRunningRegistry.js +52 -0
- package/build/services/MiniappRunningRegistry.js.map +1 -0
- package/build/services/NativeHttpResponse.d.ts +3 -0
- package/build/services/NativeHttpResponse.d.ts.map +1 -0
- package/build/services/NativeHttpResponse.js +6 -0
- package/build/services/NativeHttpResponse.js.map +1 -0
- package/build/services/NavigationHandlers.d.ts +90 -0
- package/build/services/NavigationHandlers.d.ts.map +1 -0
- package/build/services/NavigationHandlers.js +379 -0
- package/build/services/NavigationHandlers.js.map +1 -0
- package/build/services/NavigationService.d.ts +254 -0
- package/build/services/NavigationService.d.ts.map +1 -0
- package/build/services/NavigationService.js +553 -0
- package/build/services/NavigationService.js.map +1 -0
- package/build/services/NotificationsEmitter.d.ts +28 -0
- package/build/services/NotificationsEmitter.d.ts.map +1 -0
- package/build/services/NotificationsEmitter.js +22 -0
- package/build/services/NotificationsEmitter.js.map +1 -0
- package/build/services/OfflineSpeechModelService.d.ts +33 -0
- package/build/services/OfflineSpeechModelService.d.ts.map +1 -0
- package/build/services/OfflineSpeechModelService.js +136 -0
- package/build/services/OfflineSpeechModelService.js.map +1 -0
- package/build/services/OtaInstallCoordinator.d.ts +195 -0
- package/build/services/OtaInstallCoordinator.d.ts.map +1 -0
- package/build/services/OtaInstallCoordinator.js +1047 -0
- package/build/services/OtaInstallCoordinator.js.map +1 -0
- package/build/services/OtaService.d.ts +3 -0
- package/build/services/OtaService.d.ts.map +1 -0
- package/build/services/OtaService.js +65 -0
- package/build/services/OtaService.js.map +1 -0
- package/build/services/OtaUpdateCheckService.d.ts +65 -0
- package/build/services/OtaUpdateCheckService.d.ts.map +1 -0
- package/build/services/OtaUpdateCheckService.js +260 -0
- package/build/services/OtaUpdateCheckService.js.map +1 -0
- package/build/services/PairingIdentity.d.ts +80 -0
- package/build/services/PairingIdentity.d.ts.map +1 -0
- package/build/services/PairingIdentity.js +145 -0
- package/build/services/PairingIdentity.js.map +1 -0
- package/build/services/PhoneCalendarHelpers.d.ts +32 -0
- package/build/services/PhoneCalendarHelpers.d.ts.map +1 -0
- package/build/services/PhoneCalendarHelpers.js +157 -0
- package/build/services/PhoneCalendarHelpers.js.map +1 -0
- package/build/services/PhoneCalendarService.d.ts +5 -0
- package/build/services/PhoneCalendarService.d.ts.map +1 -0
- package/build/services/PhoneCalendarService.js +24 -0
- package/build/services/PhoneCalendarService.js.map +1 -0
- package/build/services/PhoneCameraFovCoordinator.d.ts +28 -0
- package/build/services/PhoneCameraFovCoordinator.d.ts.map +1 -0
- package/build/services/PhoneCameraFovCoordinator.js +180 -0
- package/build/services/PhoneCameraFovCoordinator.js.map +1 -0
- package/build/services/PhoneLocationService.d.ts +36 -0
- package/build/services/PhoneLocationService.d.ts.map +1 -0
- package/build/services/PhoneLocationService.js +115 -0
- package/build/services/PhoneLocationService.js.map +1 -0
- package/build/services/PhoneNotificationsSync.d.ts +3 -0
- package/build/services/PhoneNotificationsSync.d.ts.map +1 -0
- package/build/services/PhoneNotificationsSync.js +35 -0
- package/build/services/PhoneNotificationsSync.js.map +1 -0
- package/build/services/PhonePhotoCoordinator.d.ts +103 -0
- package/build/services/PhonePhotoCoordinator.d.ts.map +1 -0
- package/build/services/PhonePhotoCoordinator.js +326 -0
- package/build/services/PhonePhotoCoordinator.js.map +1 -0
- package/build/services/PhoneStreamCoordinator.d.ts +168 -0
- package/build/services/PhoneStreamCoordinator.d.ts.map +1 -0
- package/build/services/PhoneStreamCoordinator.js +632 -0
- package/build/services/PhoneStreamCoordinator.js.map +1 -0
- package/build/services/PhoneVideoCoordinator.d.ts +50 -0
- package/build/services/PhoneVideoCoordinator.d.ts.map +1 -0
- package/build/services/PhoneVideoCoordinator.js +147 -0
- package/build/services/PhoneVideoCoordinator.js.map +1 -0
- package/build/services/STTModelManager.d.ts +65 -0
- package/build/services/STTModelManager.d.ts.map +1 -0
- package/build/services/STTModelManager.js +292 -0
- package/build/services/STTModelManager.js.map +1 -0
- package/build/services/SceneRenderer.d.ts +90 -0
- package/build/services/SceneRenderer.d.ts.map +1 -0
- package/build/services/SceneRenderer.js +248 -0
- package/build/services/SceneRenderer.js.map +1 -0
- package/build/services/SentenceTtsPipeline.d.ts +31 -0
- package/build/services/SentenceTtsPipeline.d.ts.map +1 -0
- package/build/services/SentenceTtsPipeline.js +67 -0
- package/build/services/SentenceTtsPipeline.js.map +1 -0
- package/build/services/StreamLifecycleController.d.ts +67 -0
- package/build/services/StreamLifecycleController.d.ts.map +1 -0
- package/build/services/StreamLifecycleController.js +152 -0
- package/build/services/StreamLifecycleController.js.map +1 -0
- package/build/services/TTSModelManager.d.ts +90 -0
- package/build/services/TTSModelManager.d.ts.map +1 -0
- package/build/services/TTSModelManager.js +366 -0
- package/build/services/TTSModelManager.js.map +1 -0
- package/build/services/TranscriptionRouting.d.ts +12 -0
- package/build/services/TranscriptionRouting.d.ts.map +1 -0
- package/build/services/TranscriptionRouting.js +24 -0
- package/build/services/TranscriptionRouting.js.map +1 -0
- package/build/services/WebviewBridge.d.ts +22 -0
- package/build/services/WebviewBridge.d.ts.map +1 -0
- package/build/services/WebviewBridge.js +47 -0
- package/build/services/WebviewBridge.js.map +1 -0
- package/build/services/asg/GalleryMediaIntegrityReportService.d.ts +17 -0
- package/build/services/asg/GalleryMediaIntegrityReportService.d.ts.map +1 -0
- package/build/services/asg/GalleryMediaIntegrityReportService.js +43 -0
- package/build/services/asg/GalleryMediaIntegrityReportService.js.map +1 -0
- package/build/services/asg/asgCameraApi.d.ts +205 -0
- package/build/services/asg/asgCameraApi.d.ts.map +1 -0
- package/build/services/asg/asgCameraApi.js +1410 -0
- package/build/services/asg/asgCameraApi.js.map +1 -0
- package/build/services/asg/cameraRollExportCoordinator.d.ts +60 -0
- package/build/services/asg/cameraRollExportCoordinator.d.ts.map +1 -0
- package/build/services/asg/cameraRollExportCoordinator.js +618 -0
- package/build/services/asg/cameraRollExportCoordinator.js.map +1 -0
- package/build/services/asg/cameraRollExportLedger.d.ts +44 -0
- package/build/services/asg/cameraRollExportLedger.d.ts.map +1 -0
- package/build/services/asg/cameraRollExportLedger.js +78 -0
- package/build/services/asg/cameraRollExportLedger.js.map +1 -0
- package/build/services/asg/galleryMediaValidation.d.ts +29 -0
- package/build/services/asg/galleryMediaValidation.d.ts.map +1 -0
- package/build/services/asg/galleryMediaValidation.js +149 -0
- package/build/services/asg/galleryMediaValidation.js.map +1 -0
- package/build/services/asg/galleryNotices.d.ts +33 -0
- package/build/services/asg/galleryNotices.d.ts.map +1 -0
- package/build/services/asg/galleryNotices.js +29 -0
- package/build/services/asg/galleryNotices.js.map +1 -0
- package/build/services/asg/galleryPathMigration.d.ts +3 -0
- package/build/services/asg/galleryPathMigration.d.ts.map +1 -0
- package/build/services/asg/galleryPathMigration.js +26 -0
- package/build/services/asg/galleryPathMigration.js.map +1 -0
- package/build/services/asg/gallerySettingsService.d.ts +20 -0
- package/build/services/asg/gallerySettingsService.d.ts.map +1 -0
- package/build/services/asg/gallerySettingsService.js +53 -0
- package/build/services/asg/gallerySettingsService.js.map +1 -0
- package/build/services/asg/gallerySyncNotifications.d.ts +56 -0
- package/build/services/asg/gallerySyncNotifications.d.ts.map +1 -0
- package/build/services/asg/gallerySyncNotifications.js +198 -0
- package/build/services/asg/gallerySyncNotifications.js.map +1 -0
- package/build/services/asg/gallerySyncService.d.ts +137 -0
- package/build/services/asg/gallerySyncService.d.ts.map +1 -0
- package/build/services/asg/gallerySyncService.js +1933 -0
- package/build/services/asg/gallerySyncService.js.map +1 -0
- package/build/services/asg/galleryTransferLedger.d.ts +58 -0
- package/build/services/asg/galleryTransferLedger.d.ts.map +1 -0
- package/build/services/asg/galleryTransferLedger.js +225 -0
- package/build/services/asg/galleryTransferLedger.js.map +1 -0
- package/build/services/asg/localNetworkTransport.d.ts +15 -0
- package/build/services/asg/localNetworkTransport.d.ts.map +1 -0
- package/build/services/asg/localNetworkTransport.js +144 -0
- package/build/services/asg/localNetworkTransport.js.map +1 -0
- package/build/services/asg/localStorageService.d.ts +146 -0
- package/build/services/asg/localStorageService.d.ts.map +1 -0
- package/build/services/asg/localStorageService.js +572 -0
- package/build/services/asg/localStorageService.js.map +1 -0
- package/build/services/asg/mediaProcessingQueue.d.ts +70 -0
- package/build/services/asg/mediaProcessingQueue.d.ts.map +1 -0
- package/build/services/asg/mediaProcessingQueue.js +451 -0
- package/build/services/asg/mediaProcessingQueue.js.map +1 -0
- package/build/services/asgOtaVersionUrl.d.ts +2 -0
- package/build/services/asgOtaVersionUrl.d.ts.map +1 -0
- package/build/services/asgOtaVersionUrl.js +36 -0
- package/build/services/asgOtaVersionUrl.js.map +1 -0
- package/build/services/blobPaths.d.ts +31 -0
- package/build/services/blobPaths.d.ts.map +1 -0
- package/build/services/blobPaths.js +86 -0
- package/build/services/blobPaths.js.map +1 -0
- package/build/services/cloudStreamApi.d.ts +59 -0
- package/build/services/cloudStreamApi.d.ts.map +1 -0
- package/build/services/cloudStreamApi.js +81 -0
- package/build/services/cloudStreamApi.js.map +1 -0
- package/build/services/gallerySyncClock.d.ts +17 -0
- package/build/services/gallerySyncClock.d.ts.map +1 -0
- package/build/services/gallerySyncClock.js +21 -0
- package/build/services/gallerySyncClock.js.map +1 -0
- package/build/services/glassesClockSync.d.ts +20 -0
- package/build/services/glassesClockSync.d.ts.map +1 -0
- package/build/services/glassesClockSync.js +97 -0
- package/build/services/glassesClockSync.js.map +1 -0
- package/build/services/manifestVersionGate.d.ts +28 -0
- package/build/services/manifestVersionGate.d.ts.map +1 -0
- package/build/services/manifestVersionGate.js +41 -0
- package/build/services/manifestVersionGate.js.map +1 -0
- package/build/services/mentraUiShim.d.ts +38 -0
- package/build/services/mentraUiShim.d.ts.map +1 -0
- package/build/services/mentraUiShim.js +360 -0
- package/build/services/mentraUiShim.js.map +1 -0
- package/build/services/navigation/roadNameResolver.d.ts +67 -0
- package/build/services/navigation/roadNameResolver.d.ts.map +1 -0
- package/build/services/navigation/roadNameResolver.js +96 -0
- package/build/services/navigation/roadNameResolver.js.map +1 -0
- package/build/services/navigation/routesApiCodec.d.ts +38 -0
- package/build/services/navigation/routesApiCodec.d.ts.map +1 -0
- package/build/services/navigation/routesApiCodec.js +68 -0
- package/build/services/navigation/routesApiCodec.js.map +1 -0
- package/build/services/otaDisplayState.d.ts +42 -0
- package/build/services/otaDisplayState.d.ts.map +1 -0
- package/build/services/otaDisplayState.js +92 -0
- package/build/services/otaDisplayState.js.map +1 -0
- package/build/services/otaInstallPolicy.d.ts +81 -0
- package/build/services/otaInstallPolicy.d.ts.map +1 -0
- package/build/services/otaInstallPolicy.js +96 -0
- package/build/services/otaInstallPolicy.js.map +1 -0
- package/build/services/otaLegacyMapping.d.ts +22 -0
- package/build/services/otaLegacyMapping.d.ts.map +1 -0
- package/build/services/otaLegacyMapping.js +56 -0
- package/build/services/otaLegacyMapping.js.map +1 -0
- package/build/services/slimStreamStatus.d.ts +7 -0
- package/build/services/slimStreamStatus.d.ts.map +1 -0
- package/build/services/slimStreamStatus.js +26 -0
- package/build/services/slimStreamStatus.js.map +1 -0
- package/build/stores/apps.d.ts +104 -0
- package/build/stores/apps.d.ts.map +1 -0
- package/build/stores/apps.js +492 -0
- package/build/stores/apps.js.map +1 -0
- package/build/stores/bluetoothSettingKeys.d.ts +4 -0
- package/build/stores/bluetoothSettingKeys.d.ts.map +1 -0
- package/build/stores/bluetoothSettingKeys.js +31 -0
- package/build/stores/bluetoothSettingKeys.js.map +1 -0
- package/build/stores/cloudClientStatus.d.ts +9 -0
- package/build/stores/cloudClientStatus.d.ts.map +1 -0
- package/build/stores/cloudClientStatus.js +24 -0
- package/build/stores/cloudClientStatus.js.map +1 -0
- package/build/stores/connection.d.ts +22 -0
- package/build/stores/connection.d.ts.map +1 -0
- package/build/stores/connection.js +43 -0
- package/build/stores/connection.js.map +1 -0
- package/build/stores/core.d.ts +15 -0
- package/build/stores/core.d.ts.map +1 -0
- package/build/stores/core.js +21 -0
- package/build/stores/core.js.map +1 -0
- package/build/stores/display.d.ts +24 -0
- package/build/stores/display.d.ts.map +1 -0
- package/build/stores/display.js +96 -0
- package/build/stores/display.js.map +1 -0
- package/build/stores/gallerySync.d.ts +101 -0
- package/build/stores/gallerySync.d.ts.map +1 -0
- package/build/stores/gallerySync.js +217 -0
- package/build/stores/gallerySync.js.map +1 -0
- package/build/stores/glasses.d.ts +62 -0
- package/build/stores/glasses.d.ts.map +1 -0
- package/build/stores/glasses.js +203 -0
- package/build/stores/glasses.js.map +1 -0
- package/build/stores/settings.d.ts +37 -0
- package/build/stores/settings.d.ts.map +1 -0
- package/build/stores/settings.js +922 -0
- package/build/stores/settings.js.map +1 -0
- package/build/types/applet.d.ts +96 -0
- package/build/types/applet.d.ts.map +1 -0
- package/build/types/applet.js +5 -0
- package/build/types/applet.js.map +1 -0
- package/build/types/asg.d.ts +53 -0
- package/build/types/asg.d.ts.map +1 -0
- package/build/types/asg.js +2 -0
- package/build/types/asg.js.map +1 -0
- package/build/types/capabilities/even-realities-g1.d.ts +12 -0
- package/build/types/capabilities/even-realities-g1.d.ts.map +1 -0
- package/build/types/capabilities/even-realities-g1.js +55 -0
- package/build/types/capabilities/even-realities-g1.js.map +1 -0
- package/build/types/capabilities/even-realities-g2.d.ts +12 -0
- package/build/types/capabilities/even-realities-g2.d.ts.map +1 -0
- package/build/types/capabilities/even-realities-g2.js +75 -0
- package/build/types/capabilities/even-realities-g2.js.map +1 -0
- package/build/types/capabilities/mentra-display.d.ts +12 -0
- package/build/types/capabilities/mentra-display.d.ts.map +1 -0
- package/build/types/capabilities/mentra-display.js +63 -0
- package/build/types/capabilities/mentra-display.js.map +1 -0
- package/build/types/capabilities/mentra-live.d.ts +12 -0
- package/build/types/capabilities/mentra-live.d.ts.map +1 -0
- package/build/types/capabilities/mentra-live.js +92 -0
- package/build/types/capabilities/mentra-live.js.map +1 -0
- package/build/types/capabilities/none.d.ts +13 -0
- package/build/types/capabilities/none.d.ts.map +1 -0
- package/build/types/capabilities/none.js +65 -0
- package/build/types/capabilities/none.js.map +1 -0
- package/build/types/capabilities/simulated-glasses.d.ts +13 -0
- package/build/types/capabilities/simulated-glasses.d.ts.map +1 -0
- package/build/types/capabilities/simulated-glasses.js +65 -0
- package/build/types/capabilities/simulated-glasses.js.map +1 -0
- package/build/types/capabilities/vuzix-z100.d.ts +12 -0
- package/build/types/capabilities/vuzix-z100.d.ts.map +1 -0
- package/build/types/capabilities/vuzix-z100.js +52 -0
- package/build/types/capabilities/vuzix-z100.js.map +1 -0
- package/build/types/enums.d.ts +40 -0
- package/build/types/enums.d.ts.map +1 -0
- package/build/types/enums.js +44 -0
- package/build/types/enums.js.map +1 -0
- package/build/types/hardware.d.ts +160 -0
- package/build/types/hardware.d.ts.map +1 -0
- package/build/types/hardware.js +36 -0
- package/build/types/hardware.js.map +1 -0
- package/build/types/index.d.ts +11 -0
- package/build/types/index.d.ts.map +1 -0
- package/build/types/index.js +10 -0
- package/build/types/index.js.map +1 -0
- package/build/utils/GlobalEventEmitter.d.ts +10 -0
- package/build/utils/GlobalEventEmitter.d.ts.map +1 -0
- package/build/utils/GlobalEventEmitter.js +13 -0
- package/build/utils/GlobalEventEmitter.js.map +1 -0
- package/build/utils/cloudClient/RnUdpAdapter.d.ts +3 -0
- package/build/utils/cloudClient/RnUdpAdapter.d.ts.map +1 -0
- package/build/utils/cloudClient/RnUdpAdapter.js +41 -0
- package/build/utils/cloudClient/RnUdpAdapter.js.map +1 -0
- package/build/utils/cloudClient/cloudSecureStore.d.ts +3 -0
- package/build/utils/cloudClient/cloudSecureStore.d.ts.map +1 -0
- package/build/utils/cloudClient/cloudSecureStore.js +26 -0
- package/build/utils/cloudClient/cloudSecureStore.js.map +1 -0
- package/build/utils/debouncedPatch.d.ts +6 -0
- package/build/utils/debouncedPatch.d.ts.map +1 -0
- package/build/utils/debouncedPatch.js +25 -0
- package/build/utils/debouncedPatch.js.map +1 -0
- package/build/utils/devLogging.d.ts +26 -0
- package/build/utils/devLogging.d.ts.map +1 -0
- package/build/utils/devLogging.js +116 -0
- package/build/utils/devLogging.js.map +1 -0
- package/build/utils/devMiniappLaunch.d.ts +44 -0
- package/build/utils/devMiniappLaunch.d.ts.map +1 -0
- package/build/utils/devMiniappLaunch.js +52 -0
- package/build/utils/devMiniappLaunch.js.map +1 -0
- package/build/utils/diagnosticContext.d.ts +3 -0
- package/build/utils/diagnosticContext.d.ts.map +1 -0
- package/build/utils/diagnosticContext.js +119 -0
- package/build/utils/diagnosticContext.js.map +1 -0
- package/build/utils/display/composer/ColumnComposer.d.ts +131 -0
- package/build/utils/display/composer/ColumnComposer.d.ts.map +1 -0
- package/build/utils/display/composer/ColumnComposer.js +204 -0
- package/build/utils/display/composer/ColumnComposer.js.map +1 -0
- package/build/utils/display/composer/index.d.ts +9 -0
- package/build/utils/display/composer/index.d.ts.map +1 -0
- package/build/utils/display/composer/index.js +9 -0
- package/build/utils/display/composer/index.js.map +1 -0
- package/build/utils/display/helpers/DisplayHelpers.d.ts +165 -0
- package/build/utils/display/helpers/DisplayHelpers.d.ts.map +1 -0
- package/build/utils/display/helpers/DisplayHelpers.js +312 -0
- package/build/utils/display/helpers/DisplayHelpers.js.map +1 -0
- package/build/utils/display/helpers/ScrollView.d.ts +183 -0
- package/build/utils/display/helpers/ScrollView.d.ts.map +1 -0
- package/build/utils/display/helpers/ScrollView.js +257 -0
- package/build/utils/display/helpers/ScrollView.js.map +1 -0
- package/build/utils/display/helpers/index.d.ts +11 -0
- package/build/utils/display/helpers/index.d.ts.map +1 -0
- package/build/utils/display/helpers/index.js +10 -0
- package/build/utils/display/helpers/index.js.map +1 -0
- package/build/utils/display/index.d.ts +174 -0
- package/build/utils/display/index.d.ts.map +1 -0
- package/build/utils/display/index.js +185 -0
- package/build/utils/display/index.js.map +1 -0
- package/build/utils/display/measurer/TextMeasurer.d.ts +160 -0
- package/build/utils/display/measurer/TextMeasurer.d.ts.map +1 -0
- package/build/utils/display/measurer/TextMeasurer.js +273 -0
- package/build/utils/display/measurer/TextMeasurer.js.map +1 -0
- package/build/utils/display/measurer/index.d.ts +10 -0
- package/build/utils/display/measurer/index.d.ts.map +1 -0
- package/build/utils/display/measurer/index.js +11 -0
- package/build/utils/display/measurer/index.js.map +1 -0
- package/build/utils/display/measurer/script-detection.d.ts +53 -0
- package/build/utils/display/measurer/script-detection.d.ts.map +1 -0
- package/build/utils/display/measurer/script-detection.js +184 -0
- package/build/utils/display/measurer/script-detection.js.map +1 -0
- package/build/utils/display/profiles/g1.d.ts +33 -0
- package/build/utils/display/profiles/g1.d.ts.map +1 -0
- package/build/utils/display/profiles/g1.js +213 -0
- package/build/utils/display/profiles/g1.js.map +1 -0
- package/build/utils/display/profiles/g2.d.ts +13 -0
- package/build/utils/display/profiles/g2.d.ts.map +1 -0
- package/build/utils/display/profiles/g2.js +34 -0
- package/build/utils/display/profiles/g2.js.map +1 -0
- package/build/utils/display/profiles/index.d.ts +12 -0
- package/build/utils/display/profiles/index.d.ts.map +1 -0
- package/build/utils/display/profiles/index.js +15 -0
- package/build/utils/display/profiles/index.js.map +1 -0
- package/build/utils/display/profiles/nex.d.ts +10 -0
- package/build/utils/display/profiles/nex.d.ts.map +1 -0
- package/build/utils/display/profiles/nex.js +150 -0
- package/build/utils/display/profiles/nex.js.map +1 -0
- package/build/utils/display/profiles/types.d.ts +103 -0
- package/build/utils/display/profiles/types.d.ts.map +1 -0
- package/build/utils/display/profiles/types.js +2 -0
- package/build/utils/display/profiles/types.js.map +1 -0
- package/build/utils/display/profiles/z100.d.ts +33 -0
- package/build/utils/display/profiles/z100.d.ts.map +1 -0
- package/build/utils/display/profiles/z100.js +182 -0
- package/build/utils/display/profiles/z100.js.map +1 -0
- package/build/utils/display/scene/degrade.d.ts +25 -0
- package/build/utils/display/scene/degrade.d.ts.map +1 -0
- package/build/utils/display/scene/degrade.js +64 -0
- package/build/utils/display/scene/degrade.js.map +1 -0
- package/build/utils/display/scene/differ.d.ts +38 -0
- package/build/utils/display/scene/differ.d.ts.map +1 -0
- package/build/utils/display/scene/differ.js +107 -0
- package/build/utils/display/scene/differ.js.map +1 -0
- package/build/utils/display/scene/index.d.ts +10 -0
- package/build/utils/display/scene/index.d.ts.map +1 -0
- package/build/utils/display/scene/index.js +6 -0
- package/build/utils/display/scene/index.js.map +1 -0
- package/build/utils/display/scene/process.d.ts +35 -0
- package/build/utils/display/scene/process.d.ts.map +1 -0
- package/build/utils/display/scene/process.js +187 -0
- package/build/utils/display/scene/process.js.map +1 -0
- package/build/utils/display/scene/store.d.ts +48 -0
- package/build/utils/display/scene/store.d.ts.map +1 -0
- package/build/utils/display/scene/store.js +0 -0
- package/build/utils/display/scene/store.js.map +1 -0
- package/build/utils/display/scene/types.d.ts +120 -0
- package/build/utils/display/scene/types.d.ts.map +1 -0
- package/build/utils/display/scene/types.js +0 -0
- package/build/utils/display/scene/types.js.map +1 -0
- package/build/utils/display/wrapper/TextWrapper.d.ts +102 -0
- package/build/utils/display/wrapper/TextWrapper.d.ts.map +1 -0
- package/build/utils/display/wrapper/TextWrapper.js +471 -0
- package/build/utils/display/wrapper/TextWrapper.js.map +1 -0
- package/build/utils/display/wrapper/index.d.ts +12 -0
- package/build/utils/display/wrapper/index.d.ts.map +1 -0
- package/build/utils/display/wrapper/index.js +12 -0
- package/build/utils/display/wrapper/index.js.map +1 -0
- package/build/utils/display/wrapper/types.d.ts +75 -0
- package/build/utils/display/wrapper/types.d.ts.map +1 -0
- package/build/utils/display/wrapper/types.js +11 -0
- package/build/utils/display/wrapper/types.js.map +1 -0
- package/build/utils/e2eMetrics.d.ts +6 -0
- package/build/utils/e2eMetrics.d.ts.map +1 -0
- package/build/utils/e2eMetrics.js +27 -0
- package/build/utils/e2eMetrics.js.map +1 -0
- package/build/utils/hardware/hardware.d.ts +42 -0
- package/build/utils/hardware/hardware.d.ts.map +1 -0
- package/build/utils/hardware/hardware.js +127 -0
- package/build/utils/hardware/hardware.js.map +1 -0
- package/build/utils/hardware/index.d.ts +2 -0
- package/build/utils/hardware/index.d.ts.map +1 -0
- package/build/utils/hardware/index.js +2 -0
- package/build/utils/hardware/index.js.map +1 -0
- package/build/utils/miniappGlobals.d.ts +60 -0
- package/build/utils/miniappGlobals.d.ts.map +1 -0
- package/build/utils/miniappGlobals.js +224 -0
- package/build/utils/miniappGlobals.js.map +1 -0
- package/build/utils/permissions/MediaLibraryPermissions.d.ts +45 -0
- package/build/utils/permissions/MediaLibraryPermissions.d.ts.map +1 -0
- package/build/utils/permissions/MediaLibraryPermissions.js +145 -0
- package/build/utils/permissions/MediaLibraryPermissions.js.map +1 -0
- package/build/utils/permissions/galleryDisplayName.d.ts +8 -0
- package/build/utils/permissions/galleryDisplayName.d.ts.map +1 -0
- package/build/utils/permissions/galleryDisplayName.js +25 -0
- package/build/utils/permissions/galleryDisplayName.js.map +1 -0
- package/build/utils/storage/index.d.ts +3 -0
- package/build/utils/storage/index.d.ts.map +1 -0
- package/build/utils/storage/index.js +3 -0
- package/build/utils/storage/index.js.map +1 -0
- package/build/utils/storage/storage.d.ts +24 -0
- package/build/utils/storage/storage.d.ts.map +1 -0
- package/build/utils/storage/storage.js +85 -0
- package/build/utils/storage/storage.js.map +1 -0
- package/build/utils/storage/zip.d.ts +3 -0
- package/build/utils/storage/zip.d.ts.map +1 -0
- package/build/utils/storage/zip.js +14 -0
- package/build/utils/storage/zip.js.map +1 -0
- package/build/utils/timers/index.d.ts +3 -0
- package/build/utils/timers/index.d.ts.map +1 -0
- package/build/utils/timers/index.js +3 -0
- package/build/utils/timers/index.js.map +1 -0
- package/build/utils/timers/timers.d.ts +9 -0
- package/build/utils/timers/timers.d.ts.map +1 -0
- package/build/utils/timers/timers.js +105 -0
- package/build/utils/timers/timers.js.map +1 -0
- package/package.json +120 -0
- package/src/devtools.ts +13 -0
- package/src/engine.ts +173 -0
- package/src/facades/dev.ts +198 -0
- package/src/facades/display.ts +17 -0
- package/src/facades/displayMirror.ts +33 -0
- package/src/facades/gallery.ts +69 -0
- package/src/facades/glasses.ts +206 -0
- package/src/facades/glassesSettings.ts +56 -0
- package/src/facades/glassesWifi.ts +68 -0
- package/src/facades/miniapps.ts +55 -0
- package/src/facades/notifications.ts +15 -0
- package/src/facades/ota.ts +174 -0
- package/src/facades/pairing.ts +329 -0
- package/src/facades/permissions.ts +165 -0
- package/src/facades/phoneNotifications.ts +50 -0
- package/src/facades/reports.ts +185 -0
- package/src/facades/session.ts +55 -0
- package/src/facades/settings.ts +57 -0
- package/src/facades/speech.ts +38 -0
- package/src/index.ts +191 -0
- package/src/internal.ts +159 -0
- package/src/runtime/bootstrap.ts +118 -0
- package/src/runtime/config.ts +147 -0
- package/src/runtime/streamConfig.ts +34 -0
- package/src/services/AppRegistry.ts +1190 -0
- package/src/services/AudioCloudUplink.ts +50 -0
- package/src/services/AudioPlaybackService.ts +813 -0
- package/src/services/AutomaticReportResult.ts +48 -0
- package/src/services/BlobStore.ts +746 -0
- package/src/services/CaptionsTesterReportService.ts +107 -0
- package/src/services/CloudAudioSubscriptionSync.ts +41 -0
- package/src/services/CloudClientService.ts +689 -0
- package/src/services/CloudTranscriptE2EMetrics.ts +27 -0
- package/src/services/ConnectionCoordinator.ts +65 -0
- package/src/services/DevServerBridge.ts +332 -0
- package/src/services/DeviceEventRouter.ts +238 -0
- package/src/services/DeviceStoreHydration.ts +130 -0
- package/src/services/DisplayProcessor.ts +775 -0
- package/src/services/GlassesReadiness.ts +103 -0
- package/src/services/GlassesSettingsSync.ts +134 -0
- package/src/services/GlassesStatusProjection.ts +73 -0
- package/src/services/HeadingService.ts +98 -0
- package/src/services/LocalDisplayManager.ts +703 -0
- package/src/services/LocalMiniappRuntime.ts +4213 -0
- package/src/services/LocalSttFallbackCoordinator.ts +147 -0
- package/src/services/MentraJSCrashController.ts +189 -0
- package/src/services/MentraJSCrashloopReportService.ts +66 -0
- package/src/services/MentraJSLogPipeline.ts +166 -0
- package/src/services/MentraJSRouter.ts +557 -0
- package/src/services/MentraUIRouter.ts +244 -0
- package/src/services/MicStateCoordinator.ts +94 -0
- package/src/services/MiniappEngine.ts +143 -0
- package/src/services/MiniappLauncher.ts +340 -0
- package/src/services/MiniappRunningRegistry.ts +57 -0
- package/src/services/NativeHttpResponse.ts +6 -0
- package/src/services/NavigationHandlers.ts +423 -0
- package/src/services/NavigationService.ts +731 -0
- package/src/services/NotificationsEmitter.ts +48 -0
- package/src/services/OfflineSpeechModelService.ts +168 -0
- package/src/services/OtaInstallCoordinator.ts +1205 -0
- package/src/services/OtaService.ts +83 -0
- package/src/services/OtaUpdateCheckService.ts +386 -0
- package/src/services/PairingIdentity.ts +154 -0
- package/src/services/PhoneCalendarHelpers.ts +212 -0
- package/src/services/PhoneCalendarService.ts +42 -0
- package/src/services/PhoneCameraFovCoordinator.ts +195 -0
- package/src/services/PhoneLocationService.ts +122 -0
- package/src/services/PhoneNotificationsSync.ts +44 -0
- package/src/services/PhonePhotoCoordinator.ts +409 -0
- package/src/services/PhoneStreamCoordinator.ts +777 -0
- package/src/services/PhoneVideoCoordinator.ts +189 -0
- package/src/services/STTModelManager.ts +360 -0
- package/src/services/SceneRenderer.ts +292 -0
- package/src/services/SentenceTtsPipeline.ts +106 -0
- package/src/services/StreamLifecycleController.ts +213 -0
- package/src/services/TTSModelManager.ts +466 -0
- package/src/services/TranscriptionRouting.ts +37 -0
- package/src/services/WebviewBridge.ts +50 -0
- package/src/services/asg/GalleryMediaIntegrityReportService.ts +70 -0
- package/src/services/asg/asgCameraApi.ts +1695 -0
- package/src/services/asg/cameraRollExportCoordinator.ts +627 -0
- package/src/services/asg/cameraRollExportLedger.ts +122 -0
- package/src/services/asg/galleryMediaValidation.ts +183 -0
- package/src/services/asg/galleryNotices.ts +61 -0
- package/src/services/asg/galleryPathMigration.ts +22 -0
- package/src/services/asg/gallerySettingsService.ts +68 -0
- package/src/services/asg/gallerySyncNotifications.ts +236 -0
- package/src/services/asg/gallerySyncService.ts +2269 -0
- package/src/services/asg/galleryTransferLedger.ts +312 -0
- package/src/services/asg/localNetworkTransport.ts +173 -0
- package/src/services/asg/localStorageService.ts +652 -0
- package/src/services/asg/mediaProcessingQueue.ts +518 -0
- package/src/services/asgOtaVersionUrl.ts +41 -0
- package/src/services/blobPaths.ts +86 -0
- package/src/services/cloudStreamApi.ts +154 -0
- package/src/services/gallerySyncClock.ts +39 -0
- package/src/services/glassesClockSync.ts +115 -0
- package/src/services/manifestVersionGate.ts +43 -0
- package/src/services/mentraUiShim.ts +366 -0
- package/src/services/navigation/roadNameResolver.ts +112 -0
- package/src/services/navigation/routesApiCodec.ts +69 -0
- package/src/services/otaDisplayState.ts +115 -0
- package/src/services/otaInstallPolicy.ts +106 -0
- package/src/services/otaLegacyMapping.ts +71 -0
- package/src/services/slimStreamStatus.ts +28 -0
- package/src/stores/apps.ts +614 -0
- package/src/stores/bluetoothSettingKeys.ts +36 -0
- package/src/stores/cloudClientStatus.ts +37 -0
- package/src/stores/connection.ts +69 -0
- package/src/stores/core.ts +32 -0
- package/src/stores/display.ts +121 -0
- package/src/stores/gallerySync.ts +380 -0
- package/src/stores/glasses.ts +309 -0
- package/src/stores/settings.ts +1001 -0
- package/src/types/applet.ts +112 -0
- package/src/types/asg.ts +58 -0
- package/src/types/capabilities/even-realities-g1.ts +67 -0
- package/src/types/capabilities/even-realities-g2.ts +88 -0
- package/src/types/capabilities/mentra-display.ts +75 -0
- package/src/types/capabilities/mentra-live.ts +103 -0
- package/src/types/capabilities/none.ts +76 -0
- package/src/types/capabilities/simulated-glasses.ts +76 -0
- package/src/types/capabilities/vuzix-z100.ts +64 -0
- package/src/types/enums.ts +43 -0
- package/src/types/hardware.ts +203 -0
- package/src/types/index.ts +37 -0
- package/src/utils/GlobalEventEmitter.ts +14 -0
- package/src/utils/cloudClient/RnUdpAdapter.ts +47 -0
- package/src/utils/cloudClient/cloudSecureStore.ts +28 -0
- package/src/utils/debouncedPatch.ts +28 -0
- package/src/utils/devLogging.ts +140 -0
- package/src/utils/devMiniappLaunch.ts +68 -0
- package/src/utils/diagnosticContext.ts +155 -0
- package/src/utils/display/composer/ColumnComposer.ts +285 -0
- package/src/utils/display/composer/index.ts +15 -0
- package/src/utils/display/helpers/DisplayHelpers.ts +413 -0
- package/src/utils/display/helpers/ScrollView.ts +337 -0
- package/src/utils/display/helpers/index.ts +14 -0
- package/src/utils/display/index.ts +273 -0
- package/src/utils/display/measurer/TextMeasurer.ts +346 -0
- package/src/utils/display/measurer/index.ts +21 -0
- package/src/utils/display/measurer/script-detection.ts +218 -0
- package/src/utils/display/profiles/g1.ts +236 -0
- package/src/utils/display/profiles/g2.ts +39 -0
- package/src/utils/display/profiles/index.ts +28 -0
- package/src/utils/display/profiles/nex.ts +166 -0
- package/src/utils/display/profiles/types.ts +132 -0
- package/src/utils/display/profiles/z100.ts +198 -0
- package/src/utils/display/scene/degrade.ts +80 -0
- package/src/utils/display/scene/differ.ts +128 -0
- package/src/utils/display/scene/index.ts +21 -0
- package/src/utils/display/scene/process.ts +214 -0
- package/src/utils/display/scene/store.ts +0 -0
- package/src/utils/display/scene/types.ts +0 -0
- package/src/utils/display/wrapper/TextWrapper.ts +546 -0
- package/src/utils/display/wrapper/index.ts +15 -0
- package/src/utils/display/wrapper/types.ts +102 -0
- package/src/utils/e2eMetrics.ts +30 -0
- package/src/utils/hardware/hardware.ts +166 -0
- package/src/utils/hardware/index.ts +1 -0
- package/src/utils/miniappGlobals.ts +260 -0
- package/src/utils/permissions/MediaLibraryPermissions.ts +161 -0
- package/src/utils/permissions/galleryDisplayName.ts +28 -0
- package/src/utils/storage/index.ts +2 -0
- package/src/utils/storage/storage.ts +101 -0
- package/src/utils/storage/zip.ts +13 -0
- package/src/utils/timers/index.ts +2 -0
- package/src/utils/timers/timers.ts +139 -0
|
@@ -0,0 +1,480 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview MentraJSRouter — RN-side host that bridges the per-miniapp
|
|
3
|
+
* JS contexts (iOS-JSC and Android-QuickJS via Zipline) into the existing
|
|
4
|
+
* {@link LocalMiniappRuntime} handler set.
|
|
5
|
+
*
|
|
6
|
+
* Rather than re-implement the 33 dispatch arms inline, the router
|
|
7
|
+
* consumes Crust's `mentrajs_message` Expo event and forwards its
|
|
8
|
+
* `__bridge.send(raw)` payloads to {@link LocalMiniappRuntime.handleRawMessage}.
|
|
9
|
+
* The SDK envelope shape (`{type: "DISPLAY", ...}` etc.) is unchanged from
|
|
10
|
+
* the WebView path, so every existing handler runs verbatim. What changes
|
|
11
|
+
* is the *transport*:
|
|
12
|
+
*
|
|
13
|
+
* - **Inbound** (background JS → host): `__dispatch("__bridge", "send",
|
|
14
|
+
* [rawJsonString])` → `mentrajs_message` event → router →
|
|
15
|
+
* `LocalMiniappRuntime.handleRawMessage(packageName, raw)`.
|
|
16
|
+
* - **Outbound** (host → background JS): every package registered with
|
|
17
|
+
* the router gets a `sendMessage(raw)` fn that calls
|
|
18
|
+
* `Crust.mentraJsDispatchToJs(packageName, {kind: "bridge", raw})`.
|
|
19
|
+
* The polyfill's `__deliver` recognises `kind === "bridge"` and calls
|
|
20
|
+
* `__mentraDeliverBridgeRaw(raw)`, which routes into the SDK's
|
|
21
|
+
* {@link DispatchTransport.onMessage} handler.
|
|
22
|
+
*
|
|
23
|
+
* Host-side handler bodies (display fan-out, mic state, transcription,
|
|
24
|
+
* navigation, etc.) live untouched in `LocalMiniappRuntime.ts`.
|
|
25
|
+
*
|
|
26
|
+
* Cloud-message routing (`phone_stream_status`, `phone_managed_stream_status`)
|
|
27
|
+
* goes straight through `LocalMiniappRuntime.handleCloudMessage` — nothing
|
|
28
|
+
* for the router to do; the responses arrive inside an envelope whose
|
|
29
|
+
* `sendMessage` was already registered via the same path here.
|
|
30
|
+
*
|
|
31
|
+
* The router also bridges native error / log / unhandled-rejection
|
|
32
|
+
* events (`iface: "__log"`, `iface: "__error"`) into the standard
|
|
33
|
+
* `console.*` + Sentry breadcrumb pipeline so miniapp telemetry is
|
|
34
|
+
* visible without bringing up a separate sink.
|
|
35
|
+
*/
|
|
36
|
+
import devServerBridge from "./DevServerBridge";
|
|
37
|
+
import { MentraJSLogRingBuffer, MentraJSLogThrottle, redactSecrets } from "./MentraJSLogPipeline";
|
|
38
|
+
import { islandNotifications } from "./NotificationsEmitter";
|
|
39
|
+
import { miniappRunningRegistry } from "./MiniappRunningRegistry";
|
|
40
|
+
const defaultLogger = {
|
|
41
|
+
log: (m, p) => console.log(`[MentraJSRouter] ${m}`, p ?? ""),
|
|
42
|
+
warn: (m, p) => console.warn(`[MentraJSRouter] ${m}`, p ?? ""),
|
|
43
|
+
error: (m, p) => console.error(`[MentraJSRouter] ${m}`, p ?? ""),
|
|
44
|
+
};
|
|
45
|
+
export class MentraJSRouter {
|
|
46
|
+
runtime;
|
|
47
|
+
crust;
|
|
48
|
+
logger;
|
|
49
|
+
subscription = null;
|
|
50
|
+
registered = new Set();
|
|
51
|
+
/** Cached spawn arguments so the crash controller can respawn after a backoff. */
|
|
52
|
+
spawnCache = new Map();
|
|
53
|
+
/** Active respawn timers (so unregister() can cancel a pending respawn). */
|
|
54
|
+
respawnTimers = new Map();
|
|
55
|
+
/**
|
|
56
|
+
* Optional crash controller. When wired, every `__error` frame from a
|
|
57
|
+
* JSContext drives the state machine; an Outcome with
|
|
58
|
+
* scheduleRespawnAfterMs queues a setTimeout that re-spawns the
|
|
59
|
+
* miniapp's last-known JS source after the backoff delay.
|
|
60
|
+
*/
|
|
61
|
+
crashController = null;
|
|
62
|
+
/** Hook called when a package transitions to CRASHLOOP_DISABLED. */
|
|
63
|
+
onCrashloop = null;
|
|
64
|
+
/** Hook called on the 2nd-within-window crash (toast UX). */
|
|
65
|
+
onRestartToast = null;
|
|
66
|
+
/**
|
|
67
|
+
* Logging plumbing. Every `__log` frame passes through `redactSecrets`
|
|
68
|
+
* (token/password/etc. scrubbed), then the throttle (100/min sustained
|
|
69
|
+
* per pkg, 500 burst), then lands in the ring buffer + the host
|
|
70
|
+
* logger. The ring buffer holds the last 200 lines/pkg so a crash
|
|
71
|
+
* report can attach "last words" context.
|
|
72
|
+
*
|
|
73
|
+
* Replace with new instances in tests; production code uses the
|
|
74
|
+
* defaults.
|
|
75
|
+
*/
|
|
76
|
+
logThrottle = new MentraJSLogThrottle();
|
|
77
|
+
logRing = new MentraJSLogRingBuffer();
|
|
78
|
+
/**
|
|
79
|
+
* Optional UI router — when wired, `__bridge.send` envelopes whose
|
|
80
|
+
* inner payload type is `UI_SEND` get routed to the bound WebView
|
|
81
|
+
* instead of through LocalMiniappRuntime. Two-layer miniapps set
|
|
82
|
+
* this; legacy single-bundle WebView miniapps don't and the bridge
|
|
83
|
+
* frames pass through unchanged.
|
|
84
|
+
*/
|
|
85
|
+
uiRouter = null;
|
|
86
|
+
constructor(runtime, crust, logger = defaultLogger) {
|
|
87
|
+
this.runtime = runtime;
|
|
88
|
+
this.crust = crust;
|
|
89
|
+
this.logger = logger;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Subscribe to Crust's `mentrajs_message` event. Idempotent — calling
|
|
93
|
+
* start() twice attaches a single listener.
|
|
94
|
+
*/
|
|
95
|
+
start() {
|
|
96
|
+
if (this.subscription)
|
|
97
|
+
return;
|
|
98
|
+
this.subscription = this.crust.addListener("mentrajs_message", (raw) => {
|
|
99
|
+
try {
|
|
100
|
+
this.handleOutbound(raw);
|
|
101
|
+
}
|
|
102
|
+
catch (e) {
|
|
103
|
+
this.logger.error(`outbound handler threw`, { error: String(e), raw });
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
// A background script unregistered for missing liveness pings is dead
|
|
107
|
+
// weight: its subscriptions are gone (so the mic releases) while the
|
|
108
|
+
// webview keeps rendering stale state. Route it through the same
|
|
109
|
+
// respawn machinery as a crash so it comes back automatically, with
|
|
110
|
+
// the crash controller's backoff + crash-loop protection.
|
|
111
|
+
this.runtime.onLivenessTimeout = (packageName) => {
|
|
112
|
+
this.handleCrash(packageName, "liveness: missed pings");
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Detach the Crust subscription. The router can be restarted later
|
|
117
|
+
* with start(); registrations survive (the runtime's app map is the
|
|
118
|
+
* source of truth).
|
|
119
|
+
*/
|
|
120
|
+
stop() {
|
|
121
|
+
this.subscription?.remove();
|
|
122
|
+
this.subscription = null;
|
|
123
|
+
this.runtime.onLivenessTimeout = null;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Register a JSContext with the runtime so its handlers can fire
|
|
127
|
+
* `sendMessage(raw)` against the right context. The router builds a
|
|
128
|
+
* `sendMessage` that calls `Crust.mentraJsDispatchToJs(packageName,
|
|
129
|
+
* {kind: "bridge", raw})`; the polyfill's `__deliver` then hands the
|
|
130
|
+
* envelope to `DispatchTransport.onMessage` inside the miniapp.
|
|
131
|
+
*
|
|
132
|
+
* Mirrors `MiniappHost.registerRuntime` on the WebView side. Callers
|
|
133
|
+
* (e.g. {@link spawnAndRegister} below, or the host's miniapp launch
|
|
134
|
+
* pipeline) should call this once per spawn.
|
|
135
|
+
*/
|
|
136
|
+
registerApp(packageName, installedManifest) {
|
|
137
|
+
this.runtime.registerApp(packageName, (raw) => {
|
|
138
|
+
this.dispatchBridgeRaw(packageName, raw);
|
|
139
|
+
}, installedManifest);
|
|
140
|
+
this.registered.add(packageName);
|
|
141
|
+
// JSContext is the source-of-truth for "miniapp running". The
|
|
142
|
+
// home tile / tray reads this registry to project the `running`
|
|
143
|
+
// flag — UI WebView open/close is separate.
|
|
144
|
+
miniappRunningRegistry.add(packageName);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Convenience: spawn a JSContext via Crust, register the app, and
|
|
148
|
+
* set its declared permissions. Returns true on successful spawn.
|
|
149
|
+
*
|
|
150
|
+
* The host's miniapp launch path
|
|
151
|
+
* (`mobile/src/services/miniapps/launchLocalMiniapp.ts`) calls this
|
|
152
|
+
* once per JSContext mount.
|
|
153
|
+
*/
|
|
154
|
+
async spawnAndRegister(packageName, miniappJs, options) {
|
|
155
|
+
if (!this.crust.mentraJsSpawn) {
|
|
156
|
+
this.logger.warn("mentraJsSpawn not available — host binding missing native function");
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
const polyfill = this.crust.mentraJsLoadPolyfillBundle?.() ?? "";
|
|
160
|
+
if (!polyfill) {
|
|
161
|
+
this.logger.warn(`no polyfill bundle loaded for ${packageName}; spawn will likely fail`);
|
|
162
|
+
}
|
|
163
|
+
const ok = await this.crust.mentraJsSpawn(packageName, polyfill, miniappJs);
|
|
164
|
+
if (!ok) {
|
|
165
|
+
this.logger.error(`spawn failed for ${packageName}`);
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
// Two distinct permission gates:
|
|
169
|
+
// 1. Native dispatcher (JSContext → native bridge): `mentraJsSetManifest`
|
|
170
|
+
// checks per-call iface, e.g. __dispatch("mic", "start", ...) requires
|
|
171
|
+
// MICROPHONE.
|
|
172
|
+
// 2. LocalMiniappRuntime (SUBSCRIBE envelope): `registerApp(...,
|
|
173
|
+
// installedManifest)` carries the full manifest so SUBSCRIBE's gate
|
|
174
|
+
// can match stream → permission against declared types.
|
|
175
|
+
if (options?.permissions && options.permissions.length > 0) {
|
|
176
|
+
await this.crust.mentraJsSetManifest(packageName, options.permissions);
|
|
177
|
+
}
|
|
178
|
+
this.registerApp(packageName, options?.installedManifest);
|
|
179
|
+
// Cache spawn arguments so the crash controller can respawn the
|
|
180
|
+
// same code after a backoff. permissions + manifest are cached too
|
|
181
|
+
// because the native side resets setManifest on every spawn and
|
|
182
|
+
// LocalMiniappRuntime's installedManifest entry is keyed by
|
|
183
|
+
// connect-time registration.
|
|
184
|
+
this.spawnCache.set(packageName, {
|
|
185
|
+
miniappJs,
|
|
186
|
+
permissions: options?.permissions ?? [],
|
|
187
|
+
installedManifest: options?.installedManifest,
|
|
188
|
+
});
|
|
189
|
+
this.crashController?.onSpawn(packageName);
|
|
190
|
+
// Fire the `init` envelope so the polyfill's __deliver handler
|
|
191
|
+
// resolves `__mentraInitCallback(sessionId)`. The SDK's
|
|
192
|
+
// `registerMiniapp(handler)` wires that callback to construct
|
|
193
|
+
// MiniappSession and call the user's handler. Without this
|
|
194
|
+
// dispatch the user's code never runs — `registerMiniapp` just
|
|
195
|
+
// assigns to a global and waits.
|
|
196
|
+
const sessionId = `${packageName}-${Date.now().toString(36)}`;
|
|
197
|
+
void this.crust.mentraJsDispatchToJs(packageName, { kind: "init", sessionId });
|
|
198
|
+
return true;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Crash-controller integration. Called from the `__error` frame
|
|
202
|
+
* handler. The controller returns an outcome that tells us whether
|
|
203
|
+
* to respawn (with delay) or leave the context dead.
|
|
204
|
+
*/
|
|
205
|
+
handleCrash(packageName, reason) {
|
|
206
|
+
// The native context is dead the instant a crash is observed — invalidate
|
|
207
|
+
// its CONNECT handshake NOW so waitForConnect() blocks through the respawn
|
|
208
|
+
// backoff window instead of resolving immediately against the dead context
|
|
209
|
+
// (an action invoked mid-backoff would otherwise be delivered to nothing).
|
|
210
|
+
this.runtime.resetHandshake(packageName);
|
|
211
|
+
const controller = this.crashController;
|
|
212
|
+
if (!controller)
|
|
213
|
+
return;
|
|
214
|
+
const cached = this.spawnCache.get(packageName);
|
|
215
|
+
if (!cached) {
|
|
216
|
+
this.logger.warn(`crash for ${packageName} but no cached spawn args — cannot respawn`);
|
|
217
|
+
controller.onCrash(packageName, reason);
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
const outcome = controller.onCrash(packageName, reason);
|
|
221
|
+
if (outcome.surfaceCrashloopBanner) {
|
|
222
|
+
this.onCrashloop?.(packageName, reason);
|
|
223
|
+
islandNotifications.emit({ kind: "miniapp_crashloop", packageName, reason, timestamp: Date.now() });
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
if (outcome.showRestartToast) {
|
|
227
|
+
this.onRestartToast?.(packageName, reason);
|
|
228
|
+
}
|
|
229
|
+
if (outcome.scheduleRespawnAfterMs == null)
|
|
230
|
+
return;
|
|
231
|
+
// Cancel any prior pending respawn before scheduling a new one.
|
|
232
|
+
const existing = this.respawnTimers.get(packageName);
|
|
233
|
+
if (existing)
|
|
234
|
+
clearTimeout(existing);
|
|
235
|
+
const timer = setTimeout(() => {
|
|
236
|
+
this.respawnTimers.delete(packageName);
|
|
237
|
+
void (async () => {
|
|
238
|
+
try {
|
|
239
|
+
await this.crust.mentraJsKill?.(packageName);
|
|
240
|
+
}
|
|
241
|
+
catch {
|
|
242
|
+
/* native may have already torn down */
|
|
243
|
+
}
|
|
244
|
+
const ok = await this.crust.mentraJsSpawn?.(packageName, this.crust.mentraJsLoadPolyfillBundle?.() ?? "", cached.miniappJs);
|
|
245
|
+
if (!ok) {
|
|
246
|
+
this.logger.error(`crash respawn failed for ${packageName}`);
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
if (cached.permissions.length > 0) {
|
|
250
|
+
await this.crust.mentraJsSetManifest(packageName, cached.permissions);
|
|
251
|
+
}
|
|
252
|
+
this.registerApp(packageName, cached.installedManifest);
|
|
253
|
+
controller.onSpawn(packageName);
|
|
254
|
+
// Re-fire the init envelope so the respawned context's
|
|
255
|
+
// `registerMiniapp` handler runs again.
|
|
256
|
+
const sessionId = `${packageName}-${Date.now().toString(36)}`;
|
|
257
|
+
void this.crust.mentraJsDispatchToJs(packageName, { kind: "init", sessionId });
|
|
258
|
+
this.logger.log(`respawned ${packageName} after crash`);
|
|
259
|
+
})();
|
|
260
|
+
}, outcome.scheduleRespawnAfterMs);
|
|
261
|
+
this.respawnTimers.set(packageName, timer);
|
|
262
|
+
}
|
|
263
|
+
summarizeReason(payload, method) {
|
|
264
|
+
if (payload && typeof payload === "object" && "message" in payload) {
|
|
265
|
+
return `${method}: ${payload.message}`;
|
|
266
|
+
}
|
|
267
|
+
return method;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Tear down a JSContext and unregister from the runtime. Synchronous
|
|
271
|
+
* teardown — the spec drops the 50ms WILL_DISCONNECT grace window
|
|
272
|
+
* because there's no transport handshake to flush in the JSC world.
|
|
273
|
+
*/
|
|
274
|
+
async unregister(packageName) {
|
|
275
|
+
if (!this.registered.has(packageName))
|
|
276
|
+
return;
|
|
277
|
+
// Cancel any pending crash-respawn before tearing down — we don't
|
|
278
|
+
// want a stale timer to re-spawn a miniapp the user just disabled.
|
|
279
|
+
const pending = this.respawnTimers.get(packageName);
|
|
280
|
+
if (pending) {
|
|
281
|
+
clearTimeout(pending);
|
|
282
|
+
this.respawnTimers.delete(packageName);
|
|
283
|
+
}
|
|
284
|
+
this.spawnCache.delete(packageName);
|
|
285
|
+
this.crashController?.onKill(packageName);
|
|
286
|
+
this.runtime.unregisterApp(packageName);
|
|
287
|
+
this.registered.delete(packageName);
|
|
288
|
+
// JSContext torn down → miniapp is no longer "running".
|
|
289
|
+
miniappRunningRegistry.remove(packageName);
|
|
290
|
+
if (this.crust.mentraJsKill) {
|
|
291
|
+
try {
|
|
292
|
+
await this.crust.mentraJsKill(packageName);
|
|
293
|
+
}
|
|
294
|
+
catch (e) {
|
|
295
|
+
this.logger.warn(`mentraJsKill threw for ${packageName}: ${String(e)}`);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
/** List packages the router has registered. */
|
|
300
|
+
registeredPackages() {
|
|
301
|
+
return Array.from(this.registered);
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Validate that a reused background JSContext is still responsive when its
|
|
305
|
+
* WebView comes foreground. The runtime owns the ping/timeout mechanics; the
|
|
306
|
+
* router gates this to registered packages and keeps LocalMiniappView from
|
|
307
|
+
* reaching into runtime internals.
|
|
308
|
+
*/
|
|
309
|
+
probeForegroundLiveness(packageName, reason = "foreground-open") {
|
|
310
|
+
if (!this.registered.has(packageName))
|
|
311
|
+
return;
|
|
312
|
+
this.runtime.probeForegroundLiveness(packageName, reason);
|
|
313
|
+
}
|
|
314
|
+
// ----------------------------------------------------------------
|
|
315
|
+
// Outbound message handling
|
|
316
|
+
// ----------------------------------------------------------------
|
|
317
|
+
handleOutbound(msg) {
|
|
318
|
+
const { packageName, iface, method } = msg;
|
|
319
|
+
if (!packageName || !iface || !method) {
|
|
320
|
+
this.logger.warn(`bad mentrajs_message — missing fields`, msg);
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
// 1) Bridge frames: the SDK's DispatchTransport.send(raw) lands here.
|
|
324
|
+
// Forward raw envelope into LocalMiniappRuntime.handleRawMessage
|
|
325
|
+
// so every existing handler arm runs verbatim.
|
|
326
|
+
if (iface === "__bridge" && method === "send") {
|
|
327
|
+
const raw = this.coerceArgsToBridgeRaw(msg);
|
|
328
|
+
if (raw == null) {
|
|
329
|
+
this.logger.warn(`__bridge.send had no raw payload`, msg);
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
// If the payload is a UI_SEND envelope, route it to the bound
|
|
333
|
+
// WebView instead of LocalMiniappRuntime.
|
|
334
|
+
// session.ui.send → DispatchTransport.send → here.
|
|
335
|
+
if (this.uiRouter) {
|
|
336
|
+
const innerPayload = this.peekBridgePayloadType(raw);
|
|
337
|
+
if (innerPayload?.type === "UI_SEND") {
|
|
338
|
+
this.uiRouter.routeFromBackground(packageName, innerPayload);
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
this.runtime.handleRawMessage(packageName, raw);
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
// 2) Log frames — console.* rewired through host. We tag with the
|
|
346
|
+
// packageName so Sentry breadcrumbs can be filtered downstream.
|
|
347
|
+
// Pipeline:
|
|
348
|
+
// raw args → redactSecrets → throttle decision → ring buffer
|
|
349
|
+
// → host logger (which surfaces to dev console / Sentry)
|
|
350
|
+
if (iface === "__log") {
|
|
351
|
+
const rawArgs = this.tryParseArgs(msg.argsJson);
|
|
352
|
+
const safeArgs = redactSecrets(rawArgs);
|
|
353
|
+
const decision = this.logThrottle.consume(packageName);
|
|
354
|
+
const tag = `[${packageName}]`;
|
|
355
|
+
const fn = method === "warn"
|
|
356
|
+
? this.logger.warn
|
|
357
|
+
: method === "error" || method === "fatal"
|
|
358
|
+
? this.logger.error
|
|
359
|
+
: this.logger.log;
|
|
360
|
+
// Emit a synthetic "[throttled N]" line in place of the next
|
|
361
|
+
// would-be-allowed log to summarise drops.
|
|
362
|
+
if (!decision.allowed) {
|
|
363
|
+
if (decision.throttledLine) {
|
|
364
|
+
fn(`${tag} ${decision.throttledLine}`);
|
|
365
|
+
this.logRing.push(packageName, `${decision.throttledLine}`);
|
|
366
|
+
}
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
const formatted = `${tag} console.${method}`;
|
|
370
|
+
fn(formatted, safeArgs);
|
|
371
|
+
// Stringify into the ring buffer for crash-report attachment.
|
|
372
|
+
let line;
|
|
373
|
+
try {
|
|
374
|
+
line = `${method}: ${JSON.stringify(safeArgs)}`;
|
|
375
|
+
}
|
|
376
|
+
catch {
|
|
377
|
+
line = `${method}: <unserializable>`;
|
|
378
|
+
}
|
|
379
|
+
this.logRing.push(packageName, line);
|
|
380
|
+
// Forward to the `mentra-miniapp dev` sidecar (if one is connected
|
|
381
|
+
// for this package). Source="background" so the CLI tags lines as
|
|
382
|
+
// [MentraJS]. The bridge silently drops when no dev server is up,
|
|
383
|
+
// which makes this safe to call unconditionally in prod.
|
|
384
|
+
const argsForBridge = Array.isArray(safeArgs) ? safeArgs : [safeArgs];
|
|
385
|
+
devServerBridge.forwardLog(packageName, method, argsForBridge, Date.now(), "background");
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
// 3) Error / unhandled rejection frames — surface as warnings AND
|
|
389
|
+
// drive the crash state machine when one is attached. The
|
|
390
|
+
// controller's outcome may schedule a respawn after a backoff;
|
|
391
|
+
// if it doesn't (CRASHLOOP_DISABLED), we leave the JSContext
|
|
392
|
+
// dead and let the host surface a "tap to retry" banner.
|
|
393
|
+
if (iface === "__error") {
|
|
394
|
+
const payload = this.tryParseArgs(msg.argsJson);
|
|
395
|
+
this.logger.error(`[${packageName}] ${method}`, payload);
|
|
396
|
+
if (this.crashController) {
|
|
397
|
+
// Only treat "exception" + "unhandledRejection" + "uncaught" as
|
|
398
|
+
// crash signals. `console.error` calls also flow through the
|
|
399
|
+
// log path — those don't end the JSContext.
|
|
400
|
+
const isCrash = method === "exception" || method === "unhandledRejection" || method === "uncaught";
|
|
401
|
+
if (isCrash) {
|
|
402
|
+
this.handleCrash(packageName, this.summarizeReason(payload, method));
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
// 4) Anything else is a `forwardToRn` from the dispatcher — a
|
|
408
|
+
// handler the native dispatcher didn't know about. We don't have
|
|
409
|
+
// inline handlers for any of these; the runtime's existing path
|
|
410
|
+
// treats them as legacy WebView envelopes by falling through.
|
|
411
|
+
// Log so unknown ifaces surface in dev.
|
|
412
|
+
this.logger.log(`unhandled iface=${iface} method=${method} from ${packageName}`);
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* The wire format for `__bridge.send` is `argsJson = JSON.stringify([raw])`
|
|
416
|
+
* — a single-element array containing the original raw envelope. The
|
|
417
|
+
* dispatcher passes the parsed array through as either:
|
|
418
|
+
* - `msg.args` when the dispatcher unpacked (Android path that turns
|
|
419
|
+
* `argsJson` into a List on the way to RN), or
|
|
420
|
+
* - `msg.argsJson` (iOS path that ships the string verbatim).
|
|
421
|
+
* Cover both shapes here.
|
|
422
|
+
*/
|
|
423
|
+
/**
|
|
424
|
+
* Parse a raw bridge envelope just enough to peek at the inner
|
|
425
|
+
* payload's `type` field. Used by the UI_SEND interception path.
|
|
426
|
+
* Returns null if the envelope isn't a valid bridge frame.
|
|
427
|
+
*/
|
|
428
|
+
peekBridgePayloadType(raw) {
|
|
429
|
+
try {
|
|
430
|
+
const env = JSON.parse(raw);
|
|
431
|
+
if (env && typeof env.payload === "object" && env.payload && typeof env.payload.type === "string") {
|
|
432
|
+
return env.payload;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
catch {
|
|
436
|
+
return null;
|
|
437
|
+
}
|
|
438
|
+
return null;
|
|
439
|
+
}
|
|
440
|
+
coerceArgsToBridgeRaw(msg) {
|
|
441
|
+
if (Array.isArray(msg.args)) {
|
|
442
|
+
const v = msg.args[0];
|
|
443
|
+
return typeof v === "string" ? v : null;
|
|
444
|
+
}
|
|
445
|
+
if (typeof msg.argsJson === "string") {
|
|
446
|
+
try {
|
|
447
|
+
const parsed = JSON.parse(msg.argsJson);
|
|
448
|
+
if (Array.isArray(parsed) && typeof parsed[0] === "string") {
|
|
449
|
+
return parsed[0];
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
catch {
|
|
453
|
+
// fall through
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
return null;
|
|
457
|
+
}
|
|
458
|
+
tryParseArgs(argsJson) {
|
|
459
|
+
if (!argsJson)
|
|
460
|
+
return null;
|
|
461
|
+
try {
|
|
462
|
+
return JSON.parse(argsJson);
|
|
463
|
+
}
|
|
464
|
+
catch {
|
|
465
|
+
return argsJson;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* Push a `kind="bridge"` envelope into the named JSContext's
|
|
470
|
+
* `globalThis.__deliver`. Used both by the per-app `sendMessage`
|
|
471
|
+
* registered via {@link registerApp} and by ad-hoc callers (e.g.
|
|
472
|
+
* cloud-relayed stream-status responses route through
|
|
473
|
+
* `LocalMiniappRuntime.handleCloudMessage`, which then calls the
|
|
474
|
+
* `app.sendMessage(serialized)` registered above).
|
|
475
|
+
*/
|
|
476
|
+
dispatchBridgeRaw(packageName, raw) {
|
|
477
|
+
void this.crust.mentraJsDispatchToJs(packageName, { kind: "bridge", raw });
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
//# sourceMappingURL=MentraJSRouter.js.map
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AAC,QAAQ;YAAE,OAAO,IAAI,CAAA;QAC1B,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;QAC7B,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,QAAQ,CAAA;QACjB,CAAC;IACH,CAAC;IAED;;;;;;;OAOG;IACK,iBAAiB,CAAC,WAAmB,EAAE,GAAW;QACxD,KAAK,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC,WAAW,EAAE,EAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAC,CAAC,CAAA;IAC1E,CAAC;CACF","sourcesContent":["/**\n * @fileoverview MentraJSRouter — RN-side host that bridges the per-miniapp\n * JS contexts (iOS-JSC and Android-QuickJS via Zipline) into the existing\n * {@link LocalMiniappRuntime} handler set.\n *\n * Rather than re-implement the 33 dispatch arms inline, the router\n * consumes Crust's `mentrajs_message` Expo event and forwards its\n * `__bridge.send(raw)` payloads to {@link LocalMiniappRuntime.handleRawMessage}.\n * The SDK envelope shape (`{type: \"DISPLAY\", ...}` etc.) is unchanged from\n * the WebView path, so every existing handler runs verbatim. What changes\n * is the *transport*:\n *\n * - **Inbound** (background JS → host): `__dispatch(\"__bridge\", \"send\",\n * [rawJsonString])` → `mentrajs_message` event → router →\n * `LocalMiniappRuntime.handleRawMessage(packageName, raw)`.\n * - **Outbound** (host → background JS): every package registered with\n * the router gets a `sendMessage(raw)` fn that calls\n * `Crust.mentraJsDispatchToJs(packageName, {kind: \"bridge\", raw})`.\n * The polyfill's `__deliver` recognises `kind === \"bridge\"` and calls\n * `__mentraDeliverBridgeRaw(raw)`, which routes into the SDK's\n * {@link DispatchTransport.onMessage} handler.\n *\n * Host-side handler bodies (display fan-out, mic state, transcription,\n * navigation, etc.) live untouched in `LocalMiniappRuntime.ts`.\n *\n * Cloud-message routing (`phone_stream_status`, `phone_managed_stream_status`)\n * goes straight through `LocalMiniappRuntime.handleCloudMessage` — nothing\n * for the router to do; the responses arrive inside an envelope whose\n * `sendMessage` was already registered via the same path here.\n *\n * The router also bridges native error / log / unhandled-rejection\n * events (`iface: \"__log\"`, `iface: \"__error\"`) into the standard\n * `console.*` + Sentry breadcrumb pipeline so miniapp telemetry is\n * visible without bringing up a separate sink.\n */\n\nimport type {EventSubscription} from \"expo-modules-core\"\n\nimport devServerBridge from \"./DevServerBridge\"\nimport type localMiniappRuntime from \"./LocalMiniappRuntime\"\nimport type {InstalledMiniappManifest} from \"./LocalMiniappRuntime\"\nimport type {MentraJSCrashController} from \"./MentraJSCrashController\"\nimport {MentraJSLogRingBuffer, MentraJSLogThrottle, redactSecrets} from \"./MentraJSLogPipeline\"\nimport {islandNotifications} from \"./NotificationsEmitter\"\nimport type {MentraUIRouter} from \"./MentraUIRouter\"\nimport {miniappRunningRegistry} from \"./MiniappRunningRegistry\"\n\n/** The runtime's runtime instance type — the singleton exported from\n * LocalMiniappRuntime.ts (the file's `export default` is the instance,\n * not the class).\n */\ntype LocalMiniappRuntime = typeof localMiniappRuntime\n\n/**\n * Minimal subset of the Crust native module the router uses. Keeping the\n * binding loose lets us mock the module in unit tests without bringing\n * the whole Expo module surface along.\n */\nexport interface MentraJSCrustBinding {\n mentraJsDispatchToJs(packageName: string, envelope: Record<string, unknown>): Promise<void> | void\n mentraJsSetManifest(packageName: string, permissions: string[]): Promise<void> | void\n mentraJsLoadPolyfillBundle?: () => string\n mentraJsSpawn?: (packageName: string, polyfill: string, miniappJs: string) => Promise<boolean> | boolean\n mentraJsKill?: (packageName: string) => Promise<void> | void\n mentraJsAlivePackages?: () => string[]\n addListener: (event: string, handler: (payload: Record<string, unknown>) => void) => EventSubscription\n}\n\nexport interface OutboundMessagePayload {\n packageName: string\n iface: string\n method: string\n argsJson?: string\n args?: unknown[]\n reqId?: string\n // Implementation-internal: any extra fields the dispatcher attached on\n // .forwardToRn (e.g. payload metadata) are passed through verbatim.\n [extra: string]: unknown\n}\n\nexport type RouterLogger = {\n log: (message: string, payload?: unknown) => void\n warn: (message: string, payload?: unknown) => void\n error: (message: string, payload?: unknown) => void\n}\n\nconst defaultLogger: RouterLogger = {\n log: (m, p) => console.log(`[MentraJSRouter] ${m}`, p ?? \"\"),\n\n warn: (m, p) => console.warn(`[MentraJSRouter] ${m}`, p ?? \"\"),\n\n error: (m, p) => console.error(`[MentraJSRouter] ${m}`, p ?? \"\"),\n}\n\ninterface SpawnCache {\n miniappJs: string\n permissions: string[]\n installedManifest?: InstalledMiniappManifest\n}\n\nexport class MentraJSRouter {\n private subscription: EventSubscription | null = null\n private readonly registered: Set<string> = new Set()\n /** Cached spawn arguments so the crash controller can respawn after a backoff. */\n private readonly spawnCache: Map<string, SpawnCache> = new Map()\n /** Active respawn timers (so unregister() can cancel a pending respawn). */\n private readonly respawnTimers: Map<string, ReturnType<typeof setTimeout>> = new Map()\n\n /**\n * Optional crash controller. When wired, every `__error` frame from a\n * JSContext drives the state machine; an Outcome with\n * scheduleRespawnAfterMs queues a setTimeout that re-spawns the\n * miniapp's last-known JS source after the backoff delay.\n */\n crashController: MentraJSCrashController | null = null\n\n /** Hook called when a package transitions to CRASHLOOP_DISABLED. */\n onCrashloop: ((packageName: string, reason: string) => void) | null = null\n /** Hook called on the 2nd-within-window crash (toast UX). */\n onRestartToast: ((packageName: string, reason: string) => void) | null = null\n\n /**\n * Logging plumbing. Every `__log` frame passes through `redactSecrets`\n * (token/password/etc. scrubbed), then the throttle (100/min sustained\n * per pkg, 500 burst), then lands in the ring buffer + the host\n * logger. The ring buffer holds the last 200 lines/pkg so a crash\n * report can attach \"last words\" context.\n *\n * Replace with new instances in tests; production code uses the\n * defaults.\n */\n logThrottle: MentraJSLogThrottle = new MentraJSLogThrottle()\n logRing: MentraJSLogRingBuffer = new MentraJSLogRingBuffer()\n\n /**\n * Optional UI router — when wired, `__bridge.send` envelopes whose\n * inner payload type is `UI_SEND` get routed to the bound WebView\n * instead of through LocalMiniappRuntime. Two-layer miniapps set\n * this; legacy single-bundle WebView miniapps don't and the bridge\n * frames pass through unchanged.\n */\n uiRouter: MentraUIRouter | null = null\n\n constructor(\n private readonly runtime: LocalMiniappRuntime,\n private readonly crust: MentraJSCrustBinding,\n private readonly logger: RouterLogger = defaultLogger,\n ) {}\n\n /**\n * Subscribe to Crust's `mentrajs_message` event. Idempotent — calling\n * start() twice attaches a single listener.\n */\n start(): void {\n if (this.subscription) return\n this.subscription = this.crust.addListener(\"mentrajs_message\", (raw) => {\n try {\n this.handleOutbound(raw as unknown as OutboundMessagePayload)\n } catch (e) {\n this.logger.error(`outbound handler threw`, {error: String(e), raw})\n }\n })\n // A background script unregistered for missing liveness pings is dead\n // weight: its subscriptions are gone (so the mic releases) while the\n // webview keeps rendering stale state. Route it through the same\n // respawn machinery as a crash so it comes back automatically, with\n // the crash controller's backoff + crash-loop protection.\n this.runtime.onLivenessTimeout = (packageName) => {\n this.handleCrash(packageName, \"liveness: missed pings\")\n }\n }\n\n /**\n * Detach the Crust subscription. The router can be restarted later\n * with start(); registrations survive (the runtime's app map is the\n * source of truth).\n */\n stop(): void {\n this.subscription?.remove()\n this.subscription = null\n this.runtime.onLivenessTimeout = null\n }\n\n /**\n * Register a JSContext with the runtime so its handlers can fire\n * `sendMessage(raw)` against the right context. The router builds a\n * `sendMessage` that calls `Crust.mentraJsDispatchToJs(packageName,\n * {kind: \"bridge\", raw})`; the polyfill's `__deliver` then hands the\n * envelope to `DispatchTransport.onMessage` inside the miniapp.\n *\n * Mirrors `MiniappHost.registerRuntime` on the WebView side. Callers\n * (e.g. {@link spawnAndRegister} below, or the host's miniapp launch\n * pipeline) should call this once per spawn.\n */\n registerApp(packageName: string, installedManifest?: InstalledMiniappManifest): void {\n this.runtime.registerApp(\n packageName,\n (raw: string) => {\n this.dispatchBridgeRaw(packageName, raw)\n },\n installedManifest,\n )\n this.registered.add(packageName)\n // JSContext is the source-of-truth for \"miniapp running\". The\n // home tile / tray reads this registry to project the `running`\n // flag — UI WebView open/close is separate.\n miniappRunningRegistry.add(packageName)\n }\n\n /**\n * Convenience: spawn a JSContext via Crust, register the app, and\n * set its declared permissions. Returns true on successful spawn.\n *\n * The host's miniapp launch path\n * (`mobile/src/services/miniapps/launchLocalMiniapp.ts`) calls this\n * once per JSContext mount.\n */\n async spawnAndRegister(\n packageName: string,\n miniappJs: string,\n options?: {permissions?: string[]; installedManifest?: InstalledMiniappManifest},\n ): Promise<boolean> {\n if (!this.crust.mentraJsSpawn) {\n this.logger.warn(\"mentraJsSpawn not available — host binding missing native function\")\n return false\n }\n const polyfill = this.crust.mentraJsLoadPolyfillBundle?.() ?? \"\"\n if (!polyfill) {\n this.logger.warn(`no polyfill bundle loaded for ${packageName}; spawn will likely fail`)\n }\n const ok = await this.crust.mentraJsSpawn(packageName, polyfill, miniappJs)\n if (!ok) {\n this.logger.error(`spawn failed for ${packageName}`)\n return false\n }\n // Two distinct permission gates:\n // 1. Native dispatcher (JSContext → native bridge): `mentraJsSetManifest`\n // checks per-call iface, e.g. __dispatch(\"mic\", \"start\", ...) requires\n // MICROPHONE.\n // 2. LocalMiniappRuntime (SUBSCRIBE envelope): `registerApp(...,\n // installedManifest)` carries the full manifest so SUBSCRIBE's gate\n // can match stream → permission against declared types.\n if (options?.permissions && options.permissions.length > 0) {\n await this.crust.mentraJsSetManifest(packageName, options.permissions)\n }\n this.registerApp(packageName, options?.installedManifest)\n // Cache spawn arguments so the crash controller can respawn the\n // same code after a backoff. permissions + manifest are cached too\n // because the native side resets setManifest on every spawn and\n // LocalMiniappRuntime's installedManifest entry is keyed by\n // connect-time registration.\n this.spawnCache.set(packageName, {\n miniappJs,\n permissions: options?.permissions ?? [],\n installedManifest: options?.installedManifest,\n })\n this.crashController?.onSpawn(packageName)\n\n // Fire the `init` envelope so the polyfill's __deliver handler\n // resolves `__mentraInitCallback(sessionId)`. The SDK's\n // `registerMiniapp(handler)` wires that callback to construct\n // MiniappSession and call the user's handler. Without this\n // dispatch the user's code never runs — `registerMiniapp` just\n // assigns to a global and waits.\n const sessionId = `${packageName}-${Date.now().toString(36)}`\n void this.crust.mentraJsDispatchToJs(packageName, {kind: \"init\", sessionId})\n\n return true\n }\n\n /**\n * Crash-controller integration. Called from the `__error` frame\n * handler. The controller returns an outcome that tells us whether\n * to respawn (with delay) or leave the context dead.\n */\n private handleCrash(packageName: string, reason: string): void {\n // The native context is dead the instant a crash is observed — invalidate\n // its CONNECT handshake NOW so waitForConnect() blocks through the respawn\n // backoff window instead of resolving immediately against the dead context\n // (an action invoked mid-backoff would otherwise be delivered to nothing).\n this.runtime.resetHandshake(packageName)\n const controller = this.crashController\n if (!controller) return\n const cached = this.spawnCache.get(packageName)\n if (!cached) {\n this.logger.warn(`crash for ${packageName} but no cached spawn args — cannot respawn`)\n controller.onCrash(packageName, reason)\n return\n }\n const outcome = controller.onCrash(packageName, reason)\n if (outcome.surfaceCrashloopBanner) {\n this.onCrashloop?.(packageName, reason)\n islandNotifications.emit({kind: \"miniapp_crashloop\", packageName, reason, timestamp: Date.now()})\n return\n }\n if (outcome.showRestartToast) {\n this.onRestartToast?.(packageName, reason)\n }\n if (outcome.scheduleRespawnAfterMs == null) return\n // Cancel any prior pending respawn before scheduling a new one.\n const existing = this.respawnTimers.get(packageName)\n if (existing) clearTimeout(existing)\n const timer = setTimeout(() => {\n this.respawnTimers.delete(packageName)\n void (async () => {\n try {\n await this.crust.mentraJsKill?.(packageName)\n } catch {\n /* native may have already torn down */\n }\n const ok = await this.crust.mentraJsSpawn?.(\n packageName,\n this.crust.mentraJsLoadPolyfillBundle?.() ?? \"\",\n cached.miniappJs,\n )\n if (!ok) {\n this.logger.error(`crash respawn failed for ${packageName}`)\n return\n }\n if (cached.permissions.length > 0) {\n await this.crust.mentraJsSetManifest(packageName, cached.permissions)\n }\n this.registerApp(packageName, cached.installedManifest)\n controller.onSpawn(packageName)\n // Re-fire the init envelope so the respawned context's\n // `registerMiniapp` handler runs again.\n const sessionId = `${packageName}-${Date.now().toString(36)}`\n void this.crust.mentraJsDispatchToJs(packageName, {kind: \"init\", sessionId})\n this.logger.log(`respawned ${packageName} after crash`)\n })()\n }, outcome.scheduleRespawnAfterMs)\n this.respawnTimers.set(packageName, timer)\n }\n\n private summarizeReason(payload: unknown, method: string): string {\n if (payload && typeof payload === \"object\" && \"message\" in (payload as Record<string, unknown>)) {\n return `${method}: ${(payload as {message: string}).message}`\n }\n return method\n }\n\n /**\n * Tear down a JSContext and unregister from the runtime. Synchronous\n * teardown — the spec drops the 50ms WILL_DISCONNECT grace window\n * because there's no transport handshake to flush in the JSC world.\n */\n async unregister(packageName: string): Promise<void> {\n if (!this.registered.has(packageName)) return\n // Cancel any pending crash-respawn before tearing down — we don't\n // want a stale timer to re-spawn a miniapp the user just disabled.\n const pending = this.respawnTimers.get(packageName)\n if (pending) {\n clearTimeout(pending)\n this.respawnTimers.delete(packageName)\n }\n this.spawnCache.delete(packageName)\n this.crashController?.onKill(packageName)\n this.runtime.unregisterApp(packageName)\n this.registered.delete(packageName)\n // JSContext torn down → miniapp is no longer \"running\".\n miniappRunningRegistry.remove(packageName)\n if (this.crust.mentraJsKill) {\n try {\n await this.crust.mentraJsKill(packageName)\n } catch (e) {\n this.logger.warn(`mentraJsKill threw for ${packageName}: ${String(e)}`)\n }\n }\n }\n\n /** List packages the router has registered. */\n registeredPackages(): string[] {\n return Array.from(this.registered)\n }\n\n /**\n * Validate that a reused background JSContext is still responsive when its\n * WebView comes foreground. The runtime owns the ping/timeout mechanics; the\n * router gates this to registered packages and keeps LocalMiniappView from\n * reaching into runtime internals.\n */\n probeForegroundLiveness(packageName: string, reason = \"foreground-open\"): void {\n if (!this.registered.has(packageName)) return\n this.runtime.probeForegroundLiveness(packageName, reason)\n }\n\n // ----------------------------------------------------------------\n // Outbound message handling\n // ----------------------------------------------------------------\n\n private handleOutbound(msg: OutboundMessagePayload): void {\n const {packageName, iface, method} = msg\n if (!packageName || !iface || !method) {\n this.logger.warn(`bad mentrajs_message — missing fields`, msg)\n return\n }\n\n // 1) Bridge frames: the SDK's DispatchTransport.send(raw) lands here.\n // Forward raw envelope into LocalMiniappRuntime.handleRawMessage\n // so every existing handler arm runs verbatim.\n if (iface === \"__bridge\" && method === \"send\") {\n const raw = this.coerceArgsToBridgeRaw(msg)\n if (raw == null) {\n this.logger.warn(`__bridge.send had no raw payload`, msg)\n return\n }\n // If the payload is a UI_SEND envelope, route it to the bound\n // WebView instead of LocalMiniappRuntime.\n // session.ui.send → DispatchTransport.send → here.\n if (this.uiRouter) {\n const innerPayload = this.peekBridgePayloadType(raw)\n if (innerPayload?.type === \"UI_SEND\") {\n this.uiRouter.routeFromBackground(packageName, innerPayload)\n return\n }\n }\n this.runtime.handleRawMessage(packageName, raw)\n return\n }\n\n // 2) Log frames — console.* rewired through host. We tag with the\n // packageName so Sentry breadcrumbs can be filtered downstream.\n // Pipeline:\n // raw args → redactSecrets → throttle decision → ring buffer\n // → host logger (which surfaces to dev console / Sentry)\n if (iface === \"__log\") {\n const rawArgs = this.tryParseArgs(msg.argsJson)\n const safeArgs = redactSecrets(rawArgs)\n const decision = this.logThrottle.consume(packageName)\n const tag = `[${packageName}]`\n const fn =\n method === \"warn\"\n ? this.logger.warn\n : method === \"error\" || method === \"fatal\"\n ? this.logger.error\n : this.logger.log\n // Emit a synthetic \"[throttled N]\" line in place of the next\n // would-be-allowed log to summarise drops.\n if (!decision.allowed) {\n if (decision.throttledLine) {\n fn(`${tag} ${decision.throttledLine}`)\n this.logRing.push(packageName, `${decision.throttledLine}`)\n }\n return\n }\n const formatted = `${tag} console.${method}`\n fn(formatted, safeArgs)\n // Stringify into the ring buffer for crash-report attachment.\n let line: string\n try {\n line = `${method}: ${JSON.stringify(safeArgs)}`\n } catch {\n line = `${method}: <unserializable>`\n }\n this.logRing.push(packageName, line)\n // Forward to the `mentra-miniapp dev` sidecar (if one is connected\n // for this package). Source=\"background\" so the CLI tags lines as\n // [MentraJS]. The bridge silently drops when no dev server is up,\n // which makes this safe to call unconditionally in prod.\n const argsForBridge = Array.isArray(safeArgs) ? (safeArgs as unknown[]) : [safeArgs]\n devServerBridge.forwardLog(packageName, method, argsForBridge, Date.now(), \"background\")\n return\n }\n\n // 3) Error / unhandled rejection frames — surface as warnings AND\n // drive the crash state machine when one is attached. The\n // controller's outcome may schedule a respawn after a backoff;\n // if it doesn't (CRASHLOOP_DISABLED), we leave the JSContext\n // dead and let the host surface a \"tap to retry\" banner.\n if (iface === \"__error\") {\n const payload = this.tryParseArgs(msg.argsJson)\n this.logger.error(`[${packageName}] ${method}`, payload)\n if (this.crashController) {\n // Only treat \"exception\" + \"unhandledRejection\" + \"uncaught\" as\n // crash signals. `console.error` calls also flow through the\n // log path — those don't end the JSContext.\n const isCrash = method === \"exception\" || method === \"unhandledRejection\" || method === \"uncaught\"\n if (isCrash) {\n this.handleCrash(packageName, this.summarizeReason(payload, method))\n }\n }\n return\n }\n\n // 4) Anything else is a `forwardToRn` from the dispatcher — a\n // handler the native dispatcher didn't know about. We don't have\n // inline handlers for any of these; the runtime's existing path\n // treats them as legacy WebView envelopes by falling through.\n // Log so unknown ifaces surface in dev.\n this.logger.log(`unhandled iface=${iface} method=${method} from ${packageName}`)\n }\n\n /**\n * The wire format for `__bridge.send` is `argsJson = JSON.stringify([raw])`\n * — a single-element array containing the original raw envelope. The\n * dispatcher passes the parsed array through as either:\n * - `msg.args` when the dispatcher unpacked (Android path that turns\n * `argsJson` into a List on the way to RN), or\n * - `msg.argsJson` (iOS path that ships the string verbatim).\n * Cover both shapes here.\n */\n /**\n * Parse a raw bridge envelope just enough to peek at the inner\n * payload's `type` field. Used by the UI_SEND interception path.\n * Returns null if the envelope isn't a valid bridge frame.\n */\n private peekBridgePayloadType(raw: string): {type: string; [k: string]: unknown} | null {\n try {\n const env = JSON.parse(raw) as {payload?: {type?: string}}\n if (env && typeof env.payload === \"object\" && env.payload && typeof env.payload.type === \"string\") {\n return env.payload as {type: string; [k: string]: unknown}\n }\n } catch {\n return null\n }\n return null\n }\n\n private coerceArgsToBridgeRaw(msg: OutboundMessagePayload): string | null {\n if (Array.isArray(msg.args)) {\n const v = msg.args[0]\n return typeof v === \"string\" ? v : null\n }\n if (typeof msg.argsJson === \"string\") {\n try {\n const parsed = JSON.parse(msg.argsJson) as unknown\n if (Array.isArray(parsed) && typeof parsed[0] === \"string\") {\n return parsed[0]\n }\n } catch {\n // fall through\n }\n }\n return null\n }\n\n private tryParseArgs(argsJson: string | undefined): unknown {\n if (!argsJson) return null\n try {\n return JSON.parse(argsJson)\n } catch {\n return argsJson\n }\n }\n\n /**\n * Push a `kind=\"bridge\"` envelope into the named JSContext's\n * `globalThis.__deliver`. Used both by the per-app `sendMessage`\n * registered via {@link registerApp} and by ad-hoc callers (e.g.\n * cloud-relayed stream-status responses route through\n * `LocalMiniappRuntime.handleCloudMessage`, which then calls the\n * `app.sendMessage(serialized)` registered above).\n */\n private dispatchBridgeRaw(packageName: string, raw: string): void {\n void this.crust.mentraJsDispatchToJs(packageName, {kind: \"bridge\", raw})\n }\n}\n"]}
|