Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Collapse Ensu Android domain/data modules into app-ui

Manav Rathi756c76f16a96
diff --git a/mobile/native/android/apps/ensu/app-ui/build.gradle.kts b/mobile/native/android/apps/ensu/app-ui/build.gradle.kts
index 7a2b43a69e..115a37a36e 100644
--- a/mobile/native/android/apps/ensu/app-ui/build.gradle.kts
+++ b/mobile/native/android/apps/ensu/app-ui/build.gradle.kts
@@ -4,6 +4,7 @@ import java.util.Properties
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
+ id("org.jetbrains.kotlin.plugin.serialization")
}
configurations.configureEach {
@@ -147,10 +148,14 @@ dependencies {
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.7.0")
implementation("androidx.navigation:navigation-compose:2.7.7")
implementation("com.google.accompanist:accompanist-navigation-animation:0.34.0")
- implementation(project(":domain"))
- implementation(project(":data"))
implementation(project(":rust"))
+ implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0")
+ implementation("androidx.datastore:datastore-preferences:1.1.1")
+ implementation("androidx.security:security-crypto:1.1.0-alpha06")
+ implementation("com.squareup.okhttp3:okhttp:4.12.0")
+ implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3")
+
implementation("com.github.gregcockroft:AndroidMath:v1.1.0") {
exclude(group = "com.google.guava", module = "listenablefuture")
}
diff --git a/mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/AdvancedSettingsDataStore.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/data/AdvancedSettingsDataStore.kt
similarity index 100%
rename from mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/AdvancedSettingsDataStore.kt
rename to mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/data/AdvancedSettingsDataStore.kt
diff --git a/mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/AndroidDeviceCapabilityProvider.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/data/AndroidDeviceCapabilityProvider.kt
similarity index 79%
rename from mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/AndroidDeviceCapabilityProvider.kt
rename to mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/data/AndroidDeviceCapabilityProvider.kt
index 8122fcbd8a..d75d918a46 100644
--- a/mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/AndroidDeviceCapabilityProvider.kt
+++ b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/data/AndroidDeviceCapabilityProvider.kt
@@ -4,12 +4,11 @@ import android.app.ActivityManager
import android.content.Context
import io.ente.ensu.domain.device.CHAT_MIN_RAM_BYTES
import io.ente.ensu.domain.device.ChatDeviceCapability
-import io.ente.ensu.domain.device.DeviceCapabilityProvider
-class AndroidDeviceCapabilityProvider(context: Context) : DeviceCapabilityProvider {
+class AndroidDeviceCapabilityProvider(context: Context) {
private val appContext = context.applicationContext
- override fun chatCapability(): ChatDeviceCapability {
+ fun chatCapability(): ChatDeviceCapability {
val activityManager = appContext.getSystemService(ActivityManager::class.java)
?: return ChatDeviceCapability.Unknown
val memoryInfo = ActivityManager.MemoryInfo()
diff --git a/mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/SessionPreferencesDataStore.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/data/SessionPreferencesDataStore.kt
similarity index 83%
rename from mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/SessionPreferencesDataStore.kt
rename to mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/data/SessionPreferencesDataStore.kt
index 6023722fcc..3212fdb081 100644
--- a/mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/SessionPreferencesDataStore.kt
+++ b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/data/SessionPreferencesDataStore.kt
@@ -8,27 +8,26 @@ import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.stringPreferencesKey
import androidx.datastore.preferences.preferencesDataStoreFile
import androidx.datastore.preferences.core.PreferenceDataStoreFactory
-import io.ente.ensu.domain.preferences.SessionPreferences
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import org.json.JSONObject
-class SessionPreferencesDataStore(context: Context) : SessionPreferences {
+class SessionPreferencesDataStore(context: Context) {
private val dataStore: DataStore<Preferences> = getDataStore(context.applicationContext)
- override val selectedSessionId: Flow<String?> = dataStore.data.map { preferences ->
+ val selectedSessionId: Flow<String?> = dataStore.data.map { preferences ->
preferences[Keys.SELECTED_SESSION_ID]
}
- override val sessionSummaries: Flow<Map<String, String>> = dataStore.data.map { preferences ->
+ val sessionSummaries: Flow<Map<String, String>> = dataStore.data.map { preferences ->
decodeSessionSummaries(preferences[Keys.SESSION_SUMMARIES])
}
- override val modelDownloadRequested: Flow<Boolean> = dataStore.data.map { preferences ->
+ val modelDownloadRequested: Flow<Boolean> = dataStore.data.map { preferences ->
preferences[Keys.MODEL_DOWNLOAD_REQUESTED] ?: false
}
- override suspend fun setSelectedSessionId(sessionId: String?) {
+ suspend fun setSelectedSessionId(sessionId: String?) {
dataStore.edit { preferences ->
if (sessionId == null) {
preferences.remove(Keys.SELECTED_SESSION_ID)
@@ -38,7 +37,7 @@ class SessionPreferencesDataStore(context: Context) : SessionPreferences {
}
}
- override suspend fun setSessionSummary(sessionId: String, summary: String?) {
+ suspend fun setSessionSummary(sessionId: String, summary: String?) {
dataStore.edit { preferences ->
val summaries = decodeSessionSummaries(preferences[Keys.SESSION_SUMMARIES]).toMutableMap()
if (summary.isNullOrBlank()) {
@@ -50,7 +49,7 @@ class SessionPreferencesDataStore(context: Context) : SessionPreferences {
}
}
- override suspend fun setModelDownloadRequested(requested: Boolean) {
+ suspend fun setModelDownloadRequested(requested: Boolean) {
dataStore.edit { preferences ->
preferences[Keys.MODEL_DOWNLOAD_REQUESTED] = requested
}
diff --git a/mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/chat/ChatRecovery.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/data/chat/ChatRecovery.kt
similarity index 100%
rename from mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/chat/ChatRecovery.kt
rename to mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/data/chat/ChatRecovery.kt
diff --git a/mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/chat/RustChatRepository.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/data/chat/RustChatRepository.kt
similarity index 91%
rename from mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/chat/RustChatRepository.kt
rename to mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/data/chat/RustChatRepository.kt
index f4ded02fde..c58e2c2370 100644
--- a/mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/chat/RustChatRepository.kt
+++ b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/data/chat/RustChatRepository.kt
@@ -3,7 +3,6 @@ package io.ente.ensu.data.chat
import android.content.Context
import io.ente.ensu.data.storage.CredentialStore
import io.ente.ensu.data.storage.FilePathManager
-import io.ente.ensu.domain.chat.ChatRepository
import io.ente.ensu.domain.model.Attachment
import io.ente.ensu.domain.model.AttachmentType
import io.ente.ensu.domain.model.ChatMessage
@@ -20,7 +19,7 @@ import java.io.File
class RustChatRepository(
context: Context,
private val credentialStore: CredentialStore
-) : ChatRepository {
+) {
private val filePaths = FilePathManager(context)
private val attachmentsDir = filePaths.attachmentsDir
@@ -29,7 +28,7 @@ class RustChatRepository(
private var dbKey = credentialStore.getOrCreateChatDbKey()
private var db: EnsuDb = openDb(dbFile, dbKey)
- override fun listSessions(): List<ChatSession> = withDbRecovery {
+ fun listSessions(): List<ChatSession> = withDbRecovery {
val sessions = db.listSessions()
sessions.map { session ->
val messages = runCatching { db.getMessages(session.uuid) }.getOrNull().orEmpty()
@@ -46,7 +45,7 @@ class RustChatRepository(
}
}
- override fun createSession(title: String): ChatSession = withDbRecovery {
+ fun createSession(title: String): ChatSession = withDbRecovery {
val session = db.createSession(title)
ChatSession(
id = session.uuid,
@@ -56,11 +55,11 @@ class RustChatRepository(
)
}
- override fun deleteSession(sessionId: String) = withDbRecovery {
+ fun deleteSession(sessionId: String) = withDbRecovery {
db.deleteSession(sessionId)
}
- override fun getMessages(sessionId: String): List<ChatMessage> = withDbRecovery {
+ fun getMessages(sessionId: String): List<ChatMessage> = withDbRecovery {
db.getMessages(sessionId).map { message ->
ChatMessage(
id = message.uuid,
@@ -89,7 +88,7 @@ class RustChatRepository(
}
}
- override fun insertMessage(
+ fun insertMessage(
sessionId: String,
parentId: String?,
author: MessageAuthor,
@@ -131,15 +130,15 @@ class RustChatRepository(
)
}
- override fun updateMessageText(messageId: String, text: String) = withDbRecovery {
+ fun updateMessageText(messageId: String, text: String) = withDbRecovery {
db.updateMessageText(messageId, text)
}
- override fun updateSessionTitle(sessionId: String, title: String) = withDbRecovery {
+ fun updateSessionTitle(sessionId: String, title: String) = withDbRecovery {
db.updateSessionTitle(sessionId, title)
}
- override fun deleteAllData() {
+ fun deleteAllData() {
// Full reset removes current storage plus legacy sync leftovers.
dbFile.delete()
attachmentsDbFile.delete()
diff --git a/mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/llm/EnsuRustDefaults.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/data/llm/EnsuRustDefaults.kt
similarity index 100%
rename from mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/llm/EnsuRustDefaults.kt
rename to mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/data/llm/EnsuRustDefaults.kt
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/app-ui/src/main/java/io/ente/ensu/data/llm/InferenceRsProvider.kt
similarity index 97%
rename from mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/llm/InferenceRsProvider.kt
rename to mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/data/llm/InferenceRsProvider.kt
index 372439c6a6..24ab32f5d8 100644
--- a/mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/llm/InferenceRsProvider.kt
+++ b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/data/llm/InferenceRsProvider.kt
@@ -5,13 +5,12 @@ import android.content.Context
import android.net.Uri
import android.os.Environment
import android.util.Log
-import io.ente.ensu.domain.device.DeviceCapabilityProvider
+import io.ente.ensu.data.AndroidDeviceCapabilityProvider
import io.ente.ensu.domain.device.requireChatSupported
import io.ente.ensu.domain.llm.DownloadProgress
import io.ente.ensu.domain.llm.GenerationSummary
import io.ente.ensu.domain.llm.LlmMessage
import io.ente.ensu.domain.llm.LlmModelTarget
-import io.ente.ensu.domain.llm.LlmProvider
import io.ente.ensu.domain.util.formatBytes
import io.ente.ensu.bindings.LlmContextHandle
import io.ente.ensu.bindings.LlmContextParams
@@ -55,10 +54,10 @@ import kotlin.math.max
class InferenceRsProvider(
context: Context,
private val modelDir: File,
- private val deviceCapabilityProvider: DeviceCapabilityProvider,
+ private val deviceCapabilityProvider: AndroidDeviceCapabilityProvider,
private val legacyModelDir: File? = null,
private val ioDispatcher: kotlinx.coroutines.CoroutineDispatcher = Dispatchers.IO
-) : LlmProvider {
+) {
private data class LoadedModelKey(
val id: String,
val requestedContextLength: Int?
@@ -106,7 +105,7 @@ class InferenceRsProvider(
modelDir.mkdirs()
}
- override suspend fun ensureModelReady(
+ suspend fun ensureModelReady(
target: LlmModelTarget,
onProgress: (DownloadProgress) -> Unit
) {
@@ -117,7 +116,7 @@ class InferenceRsProvider(
}
}
- override suspend fun generateChat(
+ suspend fun generateChat(
target: LlmModelTarget,
messages: List<LlmMessage>,
imageFiles: List<File>,
@@ -161,7 +160,7 @@ class InferenceRsProvider(
GenerationSummary(summary.jobId, summary.generatedTokens ?: 0, summary.totalTimeMs)
}
- override suspend fun prewarmImageInference(target: LlmModelTarget) {
+ suspend fun prewarmImageInference(target: LlmModelTarget) {
withContext(ioDispatcher) {
runCatching {
modelLoadMutex.withLock {
@@ -181,14 +180,14 @@ class InferenceRsProvider(
}
}
- override val isManualDownloadActive: Boolean get() = manualDownloadActive
+ val isManualDownloadActive: Boolean get() = manualDownloadActive
- override fun isModelDownloaded(target: LlmModelTarget): Boolean {
+ fun isModelDownloaded(target: LlmModelTarget): Boolean {
migrateLegacyDownloads(target)
return isDownloadComplete(target)
}
- override suspend fun estimateModelDownloadSize(target: LlmModelTarget): Long? = withContext(ioDispatcher) {
+ suspend fun estimateModelDownloadSize(target: LlmModelTarget): Long? = withContext(ioDispatcher) {
val modelFile = ModelDownloadSupport.modelPathFor(modelDir, target)
val mmprojFile = ModelDownloadSupport.mmprojPathFor(modelDir, target)
val mmprojUrl = target.mmprojUrl
@@ -210,7 +209,7 @@ class InferenceRsProvider(
if (sizes.isEmpty()) null else sizes.sum()
}
- override suspend fun currentDownloadProgress(target: LlmModelTarget): DownloadProgress? =
+ suspend fun currentDownloadProgress(target: LlmModelTarget): DownloadProgress? =
withContext(ioDispatcher) {
migrateLegacyDownloads(target)
val targets = ModelDownloadSupport.expectedTargets(modelDir, target)
@@ -300,7 +299,7 @@ class InferenceRsProvider(
DownloadProgress(percent = percent, status = status)
}
- override fun loadedContextLength(target: LlmModelTarget): Int? {
+ fun loadedContextLength(target: LlmModelTarget): Int? {
val modelKey = LoadedModelKey(target.id, target.contextLength)
return if (currentModelKey == modelKey && contextHandle != null && modelHandle != null) {
currentContextLength
@@ -309,7 +308,7 @@ class InferenceRsProvider(
}
}
- override fun stopGeneration() {
+ fun stopGeneration() {
val jobId = currentJobId
if (jobId != null) {
llmCancel(jobId)
@@ -318,7 +317,7 @@ class InferenceRsProvider(
}
}
- override fun resetContext() {
+ fun resetContext() {
val model = modelHandle ?: return
val contextParams = LlmContextParams(
contextSize = currentContextLength,
@@ -329,7 +328,7 @@ class InferenceRsProvider(
contextHandle = llmCreateContext(model, contextParams)
}
- override fun cancelDownload() {
+ fun cancelDownload() {
manualDownloadCancelled = true
val ids = loadAllDownloadRecords().map { it.downloadId }.distinct()
if (ids.isNotEmpty() && downloadManager != null) {
diff --git a/mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/llm/ModelDownloadSupport.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/data/llm/ModelDownloadSupport.kt
similarity index 100%
rename from mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/llm/ModelDownloadSupport.kt
rename to mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/data/llm/ModelDownloadSupport.kt
diff --git a/mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/logging/FileLogRepository.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/data/logging/FileLogRepository.kt
similarity index 97%
rename from mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/logging/FileLogRepository.kt
rename to mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/data/logging/FileLogRepository.kt
index 1ea9c5d378..114422118e 100644
--- a/mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/logging/FileLogRepository.kt
+++ b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/data/logging/FileLogRepository.kt
@@ -2,7 +2,6 @@ package io.ente.ensu.data.logging
import android.content.Context
import android.util.Log
-import io.ente.ensu.domain.logging.LogRepository
import io.ente.ensu.domain.model.LogEntry
import io.ente.ensu.domain.model.LogLevel
import kotlinx.coroutines.CoroutineScope
@@ -32,7 +31,7 @@ class FileLogRepository(
private val context: Context,
private val maxLogFiles: Int = 5,
private val maxEntriesInMemory: Int = 500
-) : LogRepository {
+) {
private val ioScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
private val writeMutex = Mutex()
@@ -43,14 +42,14 @@ class FileLogRepository(
private val logsDir: File = File(context.filesDir, "logs")
private val _logs = MutableStateFlow<List<LogEntry>>(emptyList())
- override val logs: StateFlow<List<LogEntry>> = _logs.asStateFlow()
+ val logs: StateFlow<List<LogEntry>> = _logs.asStateFlow()
init {
ensureLogDir()
pruneOldLogFiles()
}
- override fun log(level: LogLevel, message: String, details: String?, tag: String?, throwable: Throwable?) {
+ fun log(level: LogLevel, message: String, details: String? = null, tag: String? = null, throwable: Throwable? = null) {
val resolvedTag = tag ?: "ensu"
val entry = LogEntryBuilder.buildEntry(
level = level,
diff --git a/mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/logging/LogEntryBuilder.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/data/logging/LogEntryBuilder.kt
similarity index 100%
rename from mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/logging/LogEntryBuilder.kt
rename to mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/data/logging/LogEntryBuilder.kt
diff --git a/mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/logging/LogSanitizer.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/data/logging/LogSanitizer.kt
similarity index 100%
rename from mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/logging/LogSanitizer.kt
rename to mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/data/logging/LogSanitizer.kt
diff --git a/mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/storage/CredentialStore.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/data/storage/CredentialStore.kt
similarity index 100%
rename from mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/storage/CredentialStore.kt
rename to mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/data/storage/CredentialStore.kt
diff --git a/mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/storage/FilePathManager.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/data/storage/FilePathManager.kt
similarity index 100%
rename from mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/storage/FilePathManager.kt
rename to mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/data/storage/FilePathManager.kt
diff --git a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/device/ChatDeviceCapability.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/domain/device/ChatDeviceCapability.kt
similarity index 93%
rename from mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/device/ChatDeviceCapability.kt
rename to mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/domain/device/ChatDeviceCapability.kt
index b1b36e46a3..ba4d2abb9f 100644
--- a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/device/ChatDeviceCapability.kt
+++ b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/domain/device/ChatDeviceCapability.kt
@@ -22,9 +22,6 @@ sealed interface ChatDeviceCapability {
}
}
-interface DeviceCapabilityProvider {
- fun chatCapability(): ChatDeviceCapability
-}
class UnsupportedDeviceMemoryException(
val capability: ChatDeviceCapability.UnsupportedLowMemory
diff --git a/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/domain/llm/LlmModels.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/domain/llm/LlmModels.kt
new file mode 100644
index 0000000000..98ea5fe287
--- /dev/null
+++ b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/domain/llm/LlmModels.kt
@@ -0,0 +1,34 @@
+package io.ente.ensu.domain.llm
+
+
+
+data class LlmModelTarget(
+ val id: String,
+ val url: String,
+ val mmprojUrl: String? = null,
+ val contextLength: Int? = null,
+ val maxTokens: Int? = null
+)
+
+data class DownloadProgress(
+ val percent: Int,
+ val status: String
+)
+
+enum class LlmMessageRole {
+ User,
+ Assistant,
+ System
+}
+
+data class LlmMessage(
+ val text: String,
+ val role: LlmMessageRole,
+ val hasAttachments: Boolean = false
+)
+
+data class GenerationSummary(
+ val jobId: Long,
+ val generatedTokens: Int,
+ val totalTimeMs: Long?
+)
diff --git a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/model/AttachmentDownload.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/domain/model/AttachmentDownload.kt
similarity index 100%
rename from mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/model/AttachmentDownload.kt
rename to mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/domain/model/AttachmentDownload.kt
diff --git a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/model/ChatModels.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/domain/model/ChatModels.kt
similarity index 100%
rename from mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/model/ChatModels.kt
rename to mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/domain/model/ChatModels.kt
diff --git a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/model/EnsuDefaults.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/domain/model/EnsuDefaults.kt
similarity index 100%
rename from mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/model/EnsuDefaults.kt
rename to mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/domain/model/EnsuDefaults.kt
diff --git a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/model/LogEntry.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/domain/model/LogEntry.kt
similarity index 100%
rename from mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/model/LogEntry.kt
rename to mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/domain/model/LogEntry.kt
diff --git a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/model/TitleSanitizer.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/domain/model/TitleSanitizer.kt
similarity index 100%
rename from mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/model/TitleSanitizer.kt
rename to mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/domain/model/TitleSanitizer.kt
diff --git a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/state/AppState.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/domain/state/AppState.kt
similarity index 100%
rename from mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/state/AppState.kt
rename to mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/domain/state/AppState.kt
diff --git a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/state/ChatState.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/domain/state/ChatState.kt
similarity index 100%
rename from mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/state/ChatState.kt
rename to mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/domain/state/ChatState.kt
diff --git a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/state/DeveloperSettingsState.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/domain/state/DeveloperSettingsState.kt
similarity index 100%
rename from mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/state/DeveloperSettingsState.kt
rename to mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/domain/state/DeveloperSettingsState.kt
diff --git a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/state/ModelSettingsState.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/domain/state/ModelSettingsState.kt
similarity index 100%
rename from mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/state/ModelSettingsState.kt
rename to mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/domain/state/ModelSettingsState.kt
diff --git a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/store/AppStore.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/domain/store/AppStore.kt
similarity index 92%
rename from mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/store/AppStore.kt
rename to mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/domain/store/AppStore.kt
index 50fa22baa7..9a0e1123bc 100644
--- a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/store/AppStore.kt
+++ b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/domain/store/AppStore.kt
@@ -1,15 +1,15 @@
package io.ente.ensu.domain.store
-import io.ente.ensu.domain.chat.ChatRepository
+import io.ente.ensu.data.chat.RustChatRepository
import io.ente.ensu.domain.device.ChatDeviceCapability
-import io.ente.ensu.domain.device.DeviceCapabilityProvider
-import io.ente.ensu.domain.llm.LlmProvider
-import io.ente.ensu.domain.logging.LogRepository
+import io.ente.ensu.data.AndroidDeviceCapabilityProvider
+import io.ente.ensu.data.llm.InferenceRsProvider
+import io.ente.ensu.data.logging.FileLogRepository
import io.ente.ensu.domain.model.Attachment
import io.ente.ensu.domain.model.ChatMessage
import io.ente.ensu.domain.model.EnsuDefaults
import io.ente.ensu.domain.model.LogLevel
-import io.ente.ensu.domain.preferences.SessionPreferences
+import io.ente.ensu.data.SessionPreferencesDataStore
import io.ente.ensu.domain.state.AppState
import io.ente.ensu.domain.state.DeveloperSettingsState
import io.ente.ensu.domain.state.ModelSettingsState
@@ -20,12 +20,12 @@ import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch
class AppStore(
- private val sessionPreferences: SessionPreferences,
- private val chatRepository: ChatRepository,
- private val llmProvider: LlmProvider,
- private val deviceCapabilityProvider: DeviceCapabilityProvider,
+ private val sessionPreferences: SessionPreferencesDataStore,
+ private val chatRepository: RustChatRepository,
+ private val llmProvider: InferenceRsProvider,
+ private val deviceCapabilityProvider: AndroidDeviceCapabilityProvider,
val ensuDefaults: EnsuDefaults,
- private val logRepository: LogRepository,
+ private val logRepository: FileLogRepository,
private val clock: () -> Long = { System.currentTimeMillis() }
) {
private val _state = MutableStateFlow(AppState())
diff --git a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/store/AttachmentStoreActions.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/domain/store/AttachmentStoreActions.kt
similarity index 100%
rename from mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/store/AttachmentStoreActions.kt
rename to mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/domain/store/AttachmentStoreActions.kt
diff --git a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/store/ChatStoreActions.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/domain/store/ChatStoreActions.kt
similarity index 99%
rename from mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/store/ChatStoreActions.kt
rename to mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/domain/store/ChatStoreActions.kt
index f1e6b866a0..8688442318 100644
--- a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/store/ChatStoreActions.kt
+++ b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/domain/store/ChatStoreActions.kt
@@ -1,12 +1,12 @@
package io.ente.ensu.domain.store
-import io.ente.ensu.domain.chat.ChatRepository
+import io.ente.ensu.data.chat.RustChatRepository
import io.ente.ensu.domain.device.isChatSupported
-import io.ente.ensu.domain.logging.LogRepository
+import io.ente.ensu.data.logging.FileLogRepository
import io.ente.ensu.domain.llm.LlmMessage
import io.ente.ensu.domain.llm.LlmMessageRole
import io.ente.ensu.domain.llm.LlmModelTarget
-import io.ente.ensu.domain.llm.LlmProvider
+import io.ente.ensu.data.llm.InferenceRsProvider
import io.ente.ensu.domain.model.Attachment
import io.ente.ensu.domain.model.ChatMessage
import io.ente.ensu.domain.model.ChatSession
@@ -15,7 +15,7 @@ import io.ente.ensu.domain.model.LogLevel
import io.ente.ensu.domain.model.MessageAuthor
import io.ente.ensu.domain.model.sanitizeTitleText
import io.ente.ensu.domain.model.sessionTitleFromText
-import io.ente.ensu.domain.preferences.SessionPreferences
+import io.ente.ensu.data.SessionPreferencesDataStore
import io.ente.ensu.domain.state.AppState
import java.text.SimpleDateFormat
import java.util.Date
@@ -36,11 +36,11 @@ import kotlin.math.min
internal class ChatStoreActions(
private val state: MutableStateFlow<AppState>,
- private val sessionPreferences: SessionPreferences,
- private val chatRepository: ChatRepository,
- private val llmProvider: LlmProvider,
+ private val sessionPreferences: SessionPreferencesDataStore,
+ private val chatRepository: RustChatRepository,
+ private val llmProvider: InferenceRsProvider,
private val clock: () -> Long,
- private val logRepository: LogRepository,
+ private val logRepository: FileLogRepository,
private val messageStore: MutableMap<String, MutableList<ChatMessage>>,
private val attachmentActions: AttachmentStoreActions,
private val modelSettingsActions: ModelSettingsActions,
diff --git a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/store/DbLoadHelpers.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/domain/store/DbLoadHelpers.kt
similarity index 100%
rename from mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/store/DbLoadHelpers.kt
rename to mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/domain/store/DbLoadHelpers.kt
diff --git a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/store/DownloadProgressTracker.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/domain/store/DownloadProgressTracker.kt
similarity index 100%
rename from mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/store/DownloadProgressTracker.kt
rename to mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/domain/store/DownloadProgressTracker.kt
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/app-ui/src/main/java/io/ente/ensu/domain/store/ModelSettingsActions.kt
similarity index 98%
rename from mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/store/ModelSettingsActions.kt
rename to mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/domain/store/ModelSettingsActions.kt
index e3bda13767..a57cc069ac 100644
--- a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/store/ModelSettingsActions.kt
+++ b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/domain/store/ModelSettingsActions.kt
@@ -2,11 +2,11 @@ package io.ente.ensu.domain.store
import io.ente.ensu.domain.device.isChatSupported
import io.ente.ensu.domain.llm.LlmModelTarget
-import io.ente.ensu.domain.llm.LlmProvider
-import io.ente.ensu.domain.logging.LogRepository
+import io.ente.ensu.data.llm.InferenceRsProvider
+import io.ente.ensu.data.logging.FileLogRepository
import io.ente.ensu.domain.model.EnsuDefaults
import io.ente.ensu.domain.model.LogLevel
-import io.ente.ensu.domain.preferences.SessionPreferences
+import io.ente.ensu.data.SessionPreferencesDataStore
import io.ente.ensu.domain.state.AppState
import io.ente.ensu.domain.state.ModelSettingsState
import kotlinx.coroutines.CoroutineScope
@@ -19,9 +19,9 @@ import kotlinx.coroutines.isActive
internal class ModelSettingsActions(
private val state: MutableStateFlow<AppState>,
- private val sessionPreferences: SessionPreferences,
- private val llmProvider: LlmProvider,
- private val logRepository: LogRepository,
+ private val sessionPreferences: SessionPreferencesDataStore,
+ private val llmProvider: InferenceRsProvider,
+ private val logRepository: FileLogRepository,
private val ensuDefaults: EnsuDefaults
) {
private var scope: CoroutineScope? = null
diff --git a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/util/ByteFormatter.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/domain/util/ByteFormatter.kt
similarity index 100%
rename from mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/util/ByteFormatter.kt
rename to mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/domain/util/ByteFormatter.kt
diff --git a/mobile/native/android/apps/ensu/data/build.gradle.kts b/mobile/native/android/apps/ensu/data/build.gradle.kts
deleted file mode 100644
index 5a8f4e620c..0000000000
--- a/mobile/native/android/apps/ensu/data/build.gradle.kts
+++ /dev/null
@@ -1,33 +0,0 @@
-plugins {
- id("com.android.library")
- id("org.jetbrains.kotlin.android")
- id("org.jetbrains.kotlin.plugin.serialization")
-}
-
-android {
- namespace = "io.ente.ensu.data"
- compileSdk = 34
-
- defaultConfig {
- minSdk = 24
- }
-
- compileOptions {
- sourceCompatibility = JavaVersion.VERSION_17
- targetCompatibility = JavaVersion.VERSION_17
- }
-
- kotlinOptions {
- jvmTarget = "17"
- }
-}
-
-dependencies {
- implementation(project(":domain"))
- implementation(project(":rust"))
- implementation("androidx.core:core-ktx:1.12.0")
- implementation("androidx.datastore:datastore-preferences:1.1.1")
- implementation("androidx.security:security-crypto:1.1.0-alpha06")
- implementation("com.squareup.okhttp3:okhttp:4.12.0")
- implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3")
-}
diff --git a/mobile/native/android/apps/ensu/domain/build.gradle.kts b/mobile/native/android/apps/ensu/domain/build.gradle.kts
deleted file mode 100644
index 868fecc2f8..0000000000
--- a/mobile/native/android/apps/ensu/domain/build.gradle.kts
+++ /dev/null
@@ -1,11 +0,0 @@
-plugins {
- id("org.jetbrains.kotlin.jvm")
-}
-
-kotlin {
- jvmToolchain(17)
-}
-
-dependencies {
- implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0")
-}
diff --git a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/chat/ChatRepository.kt b/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/chat/ChatRepository.kt
deleted file mode 100644
index 5bcf3f86e1..0000000000
--- a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/chat/ChatRepository.kt
+++ /dev/null
@@ -1,26 +0,0 @@
-package io.ente.ensu.domain.chat
-
-import io.ente.ensu.domain.model.Attachment
-import io.ente.ensu.domain.model.ChatMessage
-import io.ente.ensu.domain.model.ChatSession
-import io.ente.ensu.domain.model.MessageAuthor
-
-interface ChatRepository {
- fun listSessions(): List<ChatSession>
- fun createSession(title: String): ChatSession
- fun deleteSession(sessionId: String)
-
- fun getMessages(sessionId: String): List<ChatMessage>
-
- fun insertMessage(
- sessionId: String,
- parentId: String?,
- author: MessageAuthor,
- text: String,
- attachments: List<Attachment>
- ): ChatMessage
-
- fun updateMessageText(messageId: String, text: String)
- fun updateSessionTitle(sessionId: String, title: String)
- fun deleteAllData()
-}
diff --git a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/llm/LlmProvider.kt b/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/llm/LlmProvider.kt
deleted file mode 100644
index e8377550b6..0000000000
--- a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/llm/LlmProvider.kt
+++ /dev/null
@@ -1,63 +0,0 @@
-package io.ente.ensu.domain.llm
-
-import java.io.File
-
-
-data class LlmModelTarget(
- val id: String,
- val url: String,
- val mmprojUrl: String? = null,
- val contextLength: Int? = null,
- val maxTokens: Int? = null
-)
-
-data class DownloadProgress(
- val percent: Int,
- val status: String
-)
-
-enum class LlmMessageRole {
- User,
- Assistant,
- System
-}
-
-data class LlmMessage(
- val text: String,
- val role: LlmMessageRole,
- val hasAttachments: Boolean = false
-)
-
-data class GenerationSummary(
- val jobId: Long,
- val generatedTokens: Int,
- val totalTimeMs: Long?
-)
-
-interface LlmProvider {
- suspend fun ensureModelReady(
- target: LlmModelTarget,
- onProgress: (DownloadProgress) -> Unit
- )
-
- suspend fun generateChat(
- target: LlmModelTarget,
- messages: List<LlmMessage>,
- imageFiles: List<File>,
- temperature: Float,
- maxTokens: Int?,
- onToken: (String) -> Unit
- ): GenerationSummary
-
- suspend fun prewarmImageInference(target: LlmModelTarget)
-
- fun isModelDownloaded(target: LlmModelTarget): Boolean
- val isManualDownloadActive: Boolean
- suspend fun estimateModelDownloadSize(target: LlmModelTarget): Long?
- suspend fun currentDownloadProgress(target: LlmModelTarget): DownloadProgress?
- fun loadedContextLength(target: LlmModelTarget): Int?
-
- fun stopGeneration()
- fun resetContext()
- fun cancelDownload()
-}
diff --git a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/logging/LogRepository.kt b/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/logging/LogRepository.kt
deleted file mode 100644
index 0c6bb18a85..0000000000
--- a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/logging/LogRepository.kt
+++ /dev/null
@@ -1,16 +0,0 @@
-package io.ente.ensu.domain.logging
-
-import io.ente.ensu.domain.model.LogEntry
-import io.ente.ensu.domain.model.LogLevel
-import kotlinx.coroutines.flow.StateFlow
-
-interface LogRepository {
- val logs: StateFlow<List<LogEntry>>
- fun log(
- level: LogLevel,
- message: String,
- details: String? = null,
- tag: String? = null,
- throwable: Throwable? = null
- )
-}
diff --git a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/preferences/SessionPreferences.kt b/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/preferences/SessionPreferences.kt
deleted file mode 100644
index e7f96febfb..0000000000
--- a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/preferences/SessionPreferences.kt
+++ /dev/null
@@ -1,12 +0,0 @@
-package io.ente.ensu.domain.preferences
-
-import kotlinx.coroutines.flow.Flow
-
-interface SessionPreferences {
- val selectedSessionId: Flow<String?>
- val sessionSummaries: Flow<Map<String, String>>
- val modelDownloadRequested: Flow<Boolean>
- suspend fun setSelectedSessionId(sessionId: String?)
- suspend fun setSessionSummary(sessionId: String, summary: String?)
- suspend fun setModelDownloadRequested(requested: Boolean)
-}
diff --git a/mobile/native/android/apps/ensu/settings.gradle.kts b/mobile/native/android/apps/ensu/settings.gradle.kts
index aad9c73e73..e934976d38 100644
--- a/mobile/native/android/apps/ensu/settings.gradle.kts
+++ b/mobile/native/android/apps/ensu/settings.gradle.kts
@@ -16,6 +16,6 @@ dependencyResolutionManagement {
}
rootProject.name = "ensu"
-include(":app-ui", ":domain", ":data", ":rust")
+include(":app-ui", ":rust")
project(":rust").projectDir = file("../../packages/rust")