π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Fix review issues in ensu model downloads and settings across all platforms
Prateek Sunalfcc58e5a3337
diff --git a/mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/llm/InferenceRsProvider.kt b/mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/llm/InferenceRsProvider.ktindex 7043ce4b43..c9c0942781 100644--- a/mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/llm/InferenceRsProvider.kt+++ b/mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/llm/InferenceRsProvider.kt@@ -77,6 +77,7 @@ class InferenceRsProvider(@Volatile private var currentModelKey: LoadedModelKey? = null@Volatile private var currentContextLength: Int? = null@Volatile private var currentJobId: Long? = null+ @Volatile private var manualDownloadCancelled = falseprivate var backendInitialized = falseinit {@@ -302,6 +303,7 @@ class InferenceRsProvider(}override fun cancelDownload() {+ manualDownloadCancelled = trueval ids = loadAllDownloadRecords().map { it.downloadId }.distinct()if (ids.isNotEmpty()) {downloadManager.remove(*ids.toLongArray())@@ -366,6 +368,10 @@ class InferenceRsProvider(target: LlmModelTarget,onProgress: (DownloadProgress) -> Unit) {+ if (externalDownloadsRoot == null) {+ awaitManualDownload(target, onProgress)+ return+ }ensureDownloadsEnqueued(target)var emptyPollCount = 0while (true) {@@ -390,6 +396,20 @@ class InferenceRsProvider(}}+ private fun awaitManualDownload(+ target: LlmModelTarget,+ onProgress: (DownloadProgress) -> Unit+ ) {+ manualDownloadCancelled = false+ val targets = ModelDownloadSupport.expectedTargets(modelDir, target)+ ModelDownloadSupport.downloadTargets(+ httpClient,+ targets,+ onProgress,+ isCancelled = { manualDownloadCancelled }+ )+ }+private fun ensureDownloadsEnqueued(target: LlmModelTarget) {val expectedTargets = ModelDownloadSupport.expectedTargets(modelDir, target)val existingRecords = loadDownloadRecords(target).associateBy { it.destinationPath }diff --git a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/store/ModelSettingsActions.kt b/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/store/ModelSettingsActions.ktindex 1b5ee3a355..ad939ffd4c 100644--- a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/store/ModelSettingsActions.kt+++ b/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/store/ModelSettingsActions.kt@@ -77,7 +77,7 @@ internal class ModelSettingsActions(isDownloading = !isFailure,downloadPercent = progress.percent.takeIf { it >= 0 },downloadStatus = progress.status,- hasRequestedModelDownload = if (isFailure) false else true+ hasRequestedModelDownload = !isFailure))}diff --git a/mobile/native/darwin/Apps/ensu/ensu/Services/ModelDownloadManager.swift b/mobile/native/darwin/Apps/ensu/ensu/Services/ModelDownloadManager.swiftindex e6e1737b25..656550a43f 100644--- a/mobile/native/darwin/Apps/ensu/ensu/Services/ModelDownloadManager.swift+++ b/mobile/native/darwin/Apps/ensu/ensu/Services/ModelDownloadManager.swift@@ -29,13 +29,11 @@ final class ModelDownloadManager: NSObject {private let syncQueue = DispatchQueue(label: "io.ente.ensu.model-download-manager")private lazy var session: URLSession = {let configuration: URLSessionConfiguration- #if os(iOS)configuration = URLSessionConfiguration.background(withIdentifier: "io.ente.ensu.model-downloads")+ #if os(iOS)configuration.sessionSendsLaunchEvents = true- configuration.isDiscretionary = false- #else- configuration = URLSessionConfiguration.default#endif+ configuration.isDiscretionary = falseconfiguration.waitsForConnectivity = truereturn URLSession(configuration: configuration, delegate: self, delegateQueue: nil)}()@@ -175,36 +173,46 @@ final class ModelDownloadManager: NSObject {}}- private func saveRecords(_ records: [String: DownloadRecord]) {+ private func mutateRecords(_ block: (inout [String: DownloadRecord]) -> Void) {syncQueue.sync {+ var records: [String: DownloadRecord]+ if let data = UserDefaults.standard.data(forKey: recordsKey),+ let decoded = try? JSONDecoder().decode([String: DownloadRecord].self, from: data) {+ records = decoded+ } else {+ records = [:]+ }+ block(&records)let data = try? JSONEncoder().encode(records)UserDefaults.standard.set(data, forKey: recordsKey)}}private func saveRecord(_ record: DownloadRecord) {- var records = loadRecords()- records[record.id] = record- saveRecords(records)+ mutateRecords { records in+ records[record.id] = record+ }}private func updateRecord(id: String, mutate: (inout DownloadRecord) -> Void) {- var records = loadRecords()- guard var record = records[id] else { return }- mutate(&record)- records[id] = record- saveRecords(records)+ mutateRecords { records in+ guard var record = records[id] else { return }+ mutate(&record)+ records[id] = record+ }}private func clearRecords(for targets: [ModelDownloadTarget]) {- var records = loadRecords()let ids = targets.map { recordId(for: $0.destination) }- ids.forEach { records.removeValue(forKey: $0) }- saveRecords(records)+ mutateRecords { records in+ ids.forEach { records.removeValue(forKey: $0) }+ }}private func clearAllRecords() {- saveRecords([:])+ mutateRecords { records in+ records.removeAll()+ }}private func markFailed(id: String, message: String) {@@ -222,9 +230,9 @@ final class ModelDownloadManager: NSObject {}private func clearRecord(id: String) {- var records = loadRecords()- records.removeValue(forKey: id)- saveRecords(records)+ mutateRecords { records in+ records.removeValue(forKey: id)+ }}}diff --git a/mobile/native/darwin/Apps/ensu/ensu/Settings/SettingsView.swift b/mobile/native/darwin/Apps/ensu/ensu/Settings/SettingsView.swiftindex 7e146a0378..eaa1780c8d 100644--- a/mobile/native/darwin/Apps/ensu/ensu/Settings/SettingsView.swift+++ b/mobile/native/darwin/Apps/ensu/ensu/Settings/SettingsView.swift@@ -15,6 +15,7 @@ struct SettingsView: View {@State private var query: String = ""@State private var showSignOutConfirm = false@State private var buildVersionTapCount = 0+ @State private var lastBuildVersionTapAt: Date?@State private var isAdvancedUnlocked = EnsuAdvancedSettings.isUnlockedvar body: some View {@@ -276,6 +277,11 @@ struct SettingsView: View {private func handleBuildVersionTap() {guard !isAdvancedUnlocked else { return }+ let now = Date()+ if let last = lastBuildVersionTapAt, now.timeIntervalSince(last) > 2 {+ buildVersionTapCount = 0+ }+ lastBuildVersionTapAt = nowbuildVersionTapCount += 1guard buildVersionTapCount >= 5 else { return }EnsuAdvancedSettings.unlock()diff --git a/web/apps/ensu/src/pages/chat.tsx b/web/apps/ensu/src/pages/chat.tsxindex 603a1a4c17..744c26baec 100644--- a/web/apps/ensu/src/pages/chat.tsx+++ b/web/apps/ensu/src/pages/chat.tsx@@ -1230,9 +1230,11 @@ const Page: React.FC = () => {contextLength?: string;maxTokens?: string;};+ const isTauri = detectTauriRuntime();+ const canMmproj = isTauri;const rawContextLength = parsed.contextLength ?? "";const clampedContextLength =- !isTauriRuntime &&+ !isTauri &&rawContextLength &&Number(rawContextLength) > DEFAULT_WEB_CONTEXT_SIZE? String(DEFAULT_WEB_CONTEXT_SIZE)@@ -1241,7 +1243,7 @@ const Page: React.FC = () => {const nextSettings = {useCustomModel: !!parsed.useCustomModel,modelUrl: parsed.modelUrl ?? "",- mmprojUrl: allowMmproj ? (parsed.mmprojUrl ?? "") : "",+ mmprojUrl: canMmproj ? (parsed.mmprojUrl ?? "") : "",contextLength: clampedContextLength,maxTokens: parsed.maxTokens ?? "",};@@ -1252,13 +1254,13 @@ const Page: React.FC = () => {}setUseCustomModel(!!parsed.useCustomModel);setModelUrl(parsed.modelUrl ?? "");- setMmprojUrl(allowMmproj ? (parsed.mmprojUrl ?? "") : "");+ setMmprojUrl(canMmproj ? (parsed.mmprojUrl ?? "") : "");setContextLength(clampedContextLength);setMaxTokens(parsed.maxTokens ?? "");} catch (error) {log.error("Failed to read model settings", error);}- }, [allowMmproj, isTauriRuntime]);+ }, []);const applyDownloadProgress = useCallback((progress: DownloadProgress) => {setDownloadStatus(progress);diff --git a/web/apps/ensu/src/services/featureFlags.ts b/web/apps/ensu/src/services/featureFlags.tsindex 4ca632041b..58dcbfb9f5 100644--- a/web/apps/ensu/src/services/featureFlags.ts+++ b/web/apps/ensu/src/services/featureFlags.ts@@ -1,4 +1,2 @@export const SIGN_IN_ENABLED = false;export const DESKTOP_IMAGE_ATTACHMENTS_ENABLED = true;-export const DEVELOPER_SETTINGS_ENABLED = false;-export const MODEL_SETTINGS_ENABLED = false;