💚 End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
llm-chat-db integrated
Prateek Sunal61e68a49585d
diff --git a/.gitignore b/.gitignoreindex a22df027b5..e56972a81c 100644--- a/.gitignore+++ b/.gitignore@@ -20,3 +20,4 @@ node_modules/# Build artifactsmobile/native/android/packages/rust/build/mobile/native/darwin/Packages/Rust/build/+target/diff --git a/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/AppViewModel.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/AppViewModel.ktindex 22a682cb0f..226aa3fe85 100644--- a/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/AppViewModel.kt+++ b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/AppViewModel.kt@@ -9,6 +9,7 @@ import io.ente.ensu.data.auth.EnsuAuthServiceimport io.ente.ensu.data.logging.InMemoryLogRepositoryimport io.ente.ensu.data.storage.CredentialStoreimport io.ente.ensu.data.llm.InferenceRsProvider+import io.ente.ensu.data.chat.RustChatRepositoryimport io.ente.ensu.domain.store.AppStoreimport kotlinx.coroutines.flow.collectLatestimport kotlinx.coroutines.launch@@ -23,7 +24,14 @@ class AppViewModel(application: Application) : AndroidViewModel(application) {private val llmProvider = InferenceRsProvider(modelDir = File(application.filesDir, "llm"))- val store = AppStore(sessionPreferences, llmProvider = llmProvider, logRepository = logRepository)+ private val chatRepository = RustChatRepository(application, credentialStore)++ val store = AppStore(+ sessionPreferences = sessionPreferences,+ chatRepository = chatRepository,+ llmProvider = llmProvider,+ logRepository = logRepository+ )val authService = EnsuAuthService(context = application,endpointPreferences = endpointPreferences,diff --git a/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/HomeView.kt b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/HomeView.ktindex 4fff2d78dd..f9252bcd1a 100644--- a/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/HomeView.kt+++ b/mobile/native/android/apps/ensu/app-ui/src/main/java/io/ente/ensu/HomeView.kt@@ -326,7 +326,8 @@ private fun buildAttachmentFromUri(attachmentsDir.mkdirs()}- val destination = File(attachmentsDir, "${UUID.randomUUID()}_$safeName")+ val attachmentId = UUID.randomUUID().toString()+ val destination = File(attachmentsDir, attachmentId)return runCatching {val inputStream = resolver.openInputStream(uri) ?: return@runCatching null@@ -339,7 +340,8 @@ private fun buildAttachmentFromUri(val finalSize = destination.length().takeIf { it > 0 } ?: size ?: 0LAttachment(- name = name ?: destination.name,+ id = attachmentId,+ name = name ?: safeName,sizeBytes = finalSize,type = type,localPath = destination.absolutePath,diff --git a/mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/SessionPreferencesExt.kt b/mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/SessionPreferencesExt.ktnew file mode 100644index 0000000000..d869823198--- /dev/null+++ b/mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/SessionPreferencesExt.kt@@ -0,0 +1,13 @@+package io.ente.ensu.data++import io.ente.ensu.domain.preferences.SessionPreferences+import kotlinx.coroutines.flow.first+import kotlinx.coroutines.runBlocking++/**+ * Small helper to synchronously read the selected session id during bootstrap.+ * This avoids adding suspend functions to AppStore's constructor.+ */+fun SessionPreferences.getSelectedSessionIdSync(): String? = runBlocking {+ selectedSessionId.first()+}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/data/src/main/java/io/ente/ensu/data/chat/RustChatRepository.ktnew file mode 100644index 0000000000..d50c66530c--- /dev/null+++ b/mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/chat/RustChatRepository.kt@@ -0,0 +1,132 @@+package io.ente.ensu.data.chat++import android.content.Context+import io.ente.ensu.data.storage.CredentialStore+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+import io.ente.ensu.domain.model.ChatSession+import io.ente.ensu.domain.model.MessageAuthor+import io.ente.labs.llmchat_db.AttachmentKind+import io.ente.labs.llmchat_db.AttachmentMeta+import io.ente.labs.llmchat_db.LlmChatDb+import java.io.File++class RustChatRepository(+ context: Context,+ credentialStore: CredentialStore+) : ChatRepository {++ private val attachmentsDir = File(context.filesDir, "attachments")+ private val db: LlmChatDb++ init {+ if (!attachmentsDir.exists()) {+ attachmentsDir.mkdirs()+ }++ val mainDb = File(context.filesDir, "llmchat.db").absolutePath+ val attachmentsDb = File(context.filesDir, "llmchat_attachments.db").absolutePath+ val key = credentialStore.getOrCreateChatDbKey()+ db = LlmChatDb.open(mainDb, attachmentsDb, key)+ }++ override fun listSessions(): List<ChatSession> {+ val sessions = db.listSessions()+ return sessions.map { session ->+ val lastMessage = runCatching { db.getMessages(session.uuid) }.getOrNull()?.lastOrNull()?.text+ ChatSession(+ id = session.uuid,+ title = session.title,+ lastMessagePreview = lastMessage,+ updatedAtMillis = session.updatedAtUs / 1000+ )+ }+ }++ override fun createSession(title: String): ChatSession {+ val session = db.createSession(title)+ return ChatSession(+ id = session.uuid,+ title = session.title,+ lastMessagePreview = null,+ updatedAtMillis = session.updatedAtUs / 1000+ )+ }++ override fun deleteSession(sessionId: String) {+ db.deleteSession(sessionId)+ }++ override fun getMessages(sessionId: String): List<ChatMessage> {+ return db.getMessages(sessionId).map { message ->+ ChatMessage(+ id = message.uuid,+ sessionId = message.sessionUuid,+ parentId = message.parentMessageUuid,+ author = when (message.sender) {+ io.ente.labs.llmchat_db.Sender.SELF_USER -> MessageAuthor.User+ io.ente.labs.llmchat_db.Sender.OTHER -> MessageAuthor.Assistant+ },+ text = message.text,+ timestampMillis = message.createdAtUs / 1000,+ attachments = message.attachments.map { meta ->+ Attachment(+ id = meta.id,+ name = meta.name,+ sizeBytes = meta.size,+ type = when (meta.kind) {+ AttachmentKind.IMAGE -> AttachmentType.Image+ AttachmentKind.DOCUMENT -> AttachmentType.Document+ },+ localPath = File(attachmentsDir, meta.id).absolutePath,+ isUploading = false+ )+ }+ )+ }+ }++ override fun insertMessage(+ sessionId: String,+ parentId: String?,+ author: MessageAuthor,+ text: String,+ attachments: List<Attachment>+ ): ChatMessage {+ val meta = attachments.map { att ->+ AttachmentMeta(+ id = att.id,+ kind = when (att.type) {+ AttachmentType.Image -> AttachmentKind.IMAGE+ AttachmentType.Document -> AttachmentKind.DOCUMENT+ },+ size = att.sizeBytes,+ name = att.name+ )+ }++ val message = db.insertMessage(+ sessionUuid = sessionId,+ sender = if (author == MessageAuthor.User) io.ente.labs.llmchat_db.Sender.SELF_USER else io.ente.labs.llmchat_db.Sender.OTHER,+ text = text,+ parentMessageUuid = parentId,+ attachments = meta+ )++ return ChatMessage(+ id = message.uuid,+ sessionId = message.sessionUuid,+ parentId = message.parentMessageUuid,+ author = author,+ text = message.text,+ timestampMillis = message.createdAtUs / 1000,+ attachments = attachments+ )+ }++ override fun updateMessageText(messageId: String, text: String) {+ db.updateMessageText(messageId, text)+ }+}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/data/src/main/java/io/ente/ensu/data/storage/CredentialStore.ktindex 91d1b98add..41801e0e84 100644--- a/mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/storage/CredentialStore.kt+++ b/mobile/native/android/apps/ensu/data/src/main/java/io/ente/ensu/data/storage/CredentialStore.kt@@ -36,6 +36,36 @@ class CredentialStore(context: Context) {fun getToken(): String? = prefs.getString(KEY_TOKEN, null)+ fun getMasterKey(): ByteArray? = prefs.getString(KEY_MASTER_KEY, null)?.let(::decode)++ fun getSecretKey(): ByteArray? = prefs.getString(KEY_SECRET_KEY, null)?.let(::decode)++ /**+ * Returns a stable 32-byte key for encrypting the local chat DB.+ *+ * Rules:+ * - If already stored, reuse it.+ * - Else, if the account master key exists and is 32 bytes, pin it as the chat DB key.+ * - Else, generate a random 32-byte key and persist it.+ */+ fun getOrCreateChatDbKey(): ByteArray {+ prefs.getString(KEY_CHAT_DB_KEY, null)?.let { existing ->+ val decoded = runCatching { decode(existing) }.getOrNull()+ if (decoded != null && decoded.size == 32) return decoded+ }++ val fromMaster = getMasterKey()+ if (fromMaster != null && fromMaster.size == 32) {+ prefs.edit().putString(KEY_CHAT_DB_KEY, encode(fromMaster)).apply()+ return fromMaster+ }++ val generated = ByteArray(32)+ java.security.SecureRandom().nextBytes(generated)+ prefs.edit().putString(KEY_CHAT_DB_KEY, encode(generated)).apply()+ return generated+ }+fun getUserId(): Long? {val value = prefs.getLong(KEY_USER_ID, -1)return if (value == -1L) null else value@@ -48,11 +78,16 @@ class CredentialStore(context: Context) {return Base64.encodeToString(bytes, Base64.NO_WRAP or Base64.URL_SAFE)}+ private fun decode(encoded: String): ByteArray {+ return Base64.decode(encoded, Base64.NO_WRAP or Base64.URL_SAFE)+ }+companion object {private const val KEY_EMAIL = "email"private const val KEY_USER_ID = "user_id"private const val KEY_MASTER_KEY = "master_key"private const val KEY_SECRET_KEY = "secret_key"private const val KEY_TOKEN = "token"+ private const val KEY_CHAT_DB_KEY = "chat_db_key"}}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.ktnew file mode 100644index 0000000000..58c9413bdc--- /dev/null+++ b/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/chat/ChatRepository.kt@@ -0,0 +1,24 @@+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)+}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/domain/src/main/kotlin/io/ente/ensu/domain/store/AppStore.ktindex 11c91ac738..63ef3e44a0 100644--- a/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/store/AppStore.kt+++ b/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/store/AppStore.kt@@ -21,13 +21,16 @@ import kotlinx.coroutines.flow.MutableStateFlowimport kotlinx.coroutines.flow.StateFlowimport kotlinx.coroutines.flow.asStateFlowimport kotlinx.coroutines.flow.collectLatest+import kotlinx.coroutines.flow.firstimport kotlinx.coroutines.flow.updateimport kotlinx.coroutines.launch+import kotlinx.coroutines.runBlockingimport kotlin.math.absimport kotlin.math.maxclass AppStore(private val sessionPreferences: SessionPreferences,+ private val chatRepository: io.ente.ensu.domain.chat.ChatRepository,private val llmProvider: LlmProvider,private val clock: () -> Long = { System.currentTimeMillis() },private val logRepository: LogRepository = NoOpLogRepository@@ -47,7 +50,7 @@ class AppStore(logRepository.log(LogLevel.Info, "Ensū started")if (_state.value.chat.sessions.isEmpty()) {- seedSessions()+ loadSessionsFromDb()}scope.launch {@@ -60,6 +63,7 @@ class AppStore(appState}}+ loadMessagesFromDb(storedId)rebuildChatState(storedId)}}@@ -83,10 +87,7 @@ class AppStore()}- val session = ChatSession(- title = "New Chat",- updatedAtMillis = clock()- )+ val session = chatRepository.createSession("New Chat")messageStore[session.id] = mutableListOf()branchSelections[session.id] = mutableMapOf()@@ -102,6 +103,7 @@ class AppStore())}+ // Session is empty, no DB load needed.rebuildChatState(session.id)logRepository.log(LogLevel.Info, "Created new session")return session.id@@ -124,6 +126,7 @@ class AppStore())}+ loadMessagesFromDb(sessionId)rebuildChatState(sessionId)logRepository.log(LogLevel.Info, "Selected session", sessionId)}@@ -263,12 +266,11 @@ class AppStore(buildSelectedPath(sessionId).lastOrNull()?.id}- val userMessage = ChatMessage(+ val userMessage = chatRepository.insertMessage(sessionId = sessionId,parentId = parentId,author = MessageAuthor.User,text = text,- timestampMillis = timestamp,attachments = attachments)@@ -426,12 +428,15 @@ class AppStore(tokenCount.toDouble() / (totalTimeMs / 1000.0)} else null- val assistantMessage = ChatMessage(+ val inserted = chatRepository.insertMessage(sessionId = sessionId,parentId = parentMessage.id,author = MessageAuthor.Assistant,text = finalText,- timestampMillis = clock(),+ attachments = emptyList()+ )++ val assistantMessage = inserted.copy(isInterrupted = interrupted,tokensPerSecond = tokensPerSecond)@@ -470,6 +475,13 @@ class AppStore(}}+ private fun loadMessagesFromDb(sessionId: String) {+ val messages = chatRepository.getMessages(sessionId)+ messageStore[sessionId] = messages.toMutableList()+ // Reset branch selections for this session. (Branch selection is computed in-memory.)+ branchSelections.getOrPut(sessionId) { mutableMapOf() }.clear()+ }+private fun rebuildChatState(sessionId: String?) {if (sessionId == null) {_state.update { appState ->@@ -682,15 +694,28 @@ class AppStore()}- private fun seedSessions() {- val now = clock()- val session = ChatSession(title = "New Chat", lastMessagePreview = null, updatedAtMillis = now)- messageStore[session.id] = mutableListOf()- branchSelections[session.id] = mutableMapOf()+ private fun loadSessionsFromDb() {+ val sessions = chatRepository.listSessions()+ val initial = if (sessions.isEmpty()) {+ listOf(chatRepository.createSession("New Chat"))+ } else {+ sessions+ }++ initial.forEach { session ->+ messageStore.getOrPut(session.id) { mutableListOf() }+ branchSelections.getOrPut(session.id) { mutableMapOf() }+ }++ val stored = runBlocking { sessionPreferences.selectedSessionId.first() }+ val current = stored?.takeIf { id -> initial.any { it.id == id } } ?: initial.first().id+_state.update { appState ->- appState.copy(chat = appState.chat.copy(sessions = listOf(session), currentSessionId = session.id))+ appState.copy(chat = appState.chat.copy(sessions = initial, currentSessionId = current))}- rebuildChatState(session.id)++ loadMessagesFromDb(current)+ rebuildChatState(current)}private data class PromptResult(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/domain/src/main/kotlin/io/ente/ensu/domain/store/DbLoadHelpers.ktnew file mode 100644index 0000000000..23ff1649db--- /dev/null+++ b/mobile/native/android/apps/ensu/domain/src/main/kotlin/io/ente/ensu/domain/store/DbLoadHelpers.kt@@ -0,0 +1,5 @@+package io.ente.ensu.domain.store++import io.ente.ensu.domain.model.ChatMessage++// Intentionally empty placeholder file.diff --git a/mobile/native/android/packages/rust/tool/build_android.sh b/mobile/native/android/packages/rust/tool/build_android.shindex d2b50542b5..129c7080d7 100755--- a/mobile/native/android/packages/rust/tool/build_android.sh+++ b/mobile/native/android/packages/rust/tool/build_android.sh@@ -3,9 +3,10 @@ set -euo pipefailROOT="$(cd "$(dirname "$0")/.." && pwd)"REPO_ROOT="$(cd "$ROOT/../../../../.." && pwd)"-UNIFFI_RUST_DIR="$REPO_ROOT/rust/inference_rs_uniffi"-CORE_ROOT="$REPO_ROOT/rust/inference_rs"-PATCH_SCRIPT="$CORE_ROOT/tool/patch_llama_mtmd.sh"+INFERENCE_UNIFFI_RUST_DIR="$REPO_ROOT/rust/inference_rs_uniffi"+CHATDB_UNIFFI_RUST_DIR="$REPO_ROOT/rust/llmchat_db_uniffi"+# Note: Older builds used to patch llama-cpp sources; this repo no longer ships that patch script.+PATCH_SCRIPT=""OUT_DIR="$ROOT/src/main/jniLibs"NDK_VERSION="27.0.12077973"NDK_ROOT_PATH="${ANDROID_HOME:-${ANDROID_SDK_ROOT:-}}/ndk/$NDK_VERSION"@@ -20,7 +21,6 @@ if [[ ! -d "$NDK_ROOT_PATH" ]]; thenexit 1fi-"$PATCH_SCRIPT"export ANDROID_NDK="$NDK_ROOT_PATH"export ANDROID_NDK_ROOT="$NDK_ROOT_PATH"@@ -29,13 +29,15 @@ export CARGO_CFG_TARGET_FEATURE="${CARGO_CFG_TARGET_FEATURE:-}"mkdir -p "$OUT_DIR"-pushd "$UNIFFI_RUST_DIR" >/dev/null-cargo ndk \- --platform 23 \- --link-libcxx-shared \- -t arm64-v8a \- -t armeabi-v7a \- -t x86_64 \- -o "$OUT_DIR" \- build --release-popd >/dev/null+for CRATE_DIR in "$INFERENCE_UNIFFI_RUST_DIR" "$CHATDB_UNIFFI_RUST_DIR"; do+ pushd "$CRATE_DIR" >/dev/null+ cargo ndk \+ --platform 23 \+ --link-libcxx-shared \+ -t arm64-v8a \+ -t armeabi-v7a \+ -t x86_64 \+ -o "$OUT_DIR" \+ build --release+ popd >/dev/null+donediff --git a/mobile/native/darwin/Apps/ensu/ensu.xcodeproj/project.pbxproj b/mobile/native/darwin/Apps/ensu/ensu.xcodeproj/project.pbxprojindex c6607c199a..d6b31dab67 100644--- a/mobile/native/darwin/Apps/ensu/ensu.xcodeproj/project.pbxproj+++ b/mobile/native/darwin/Apps/ensu/ensu.xcodeproj/project.pbxproj@@ -303,6 +303,7 @@name = "Build Rust (ensu_uniffi)";outputPaths = ("$(TARGET_TEMP_DIR)/ensu_rust/libensu_uniffi.a",+ "$(TARGET_TEMP_DIR)/ensu_rust/libllmchat_db_uniffi.a",);runOnlyForDeploymentPostprocessing = 0;shellPath = /bin/sh;@@ -318,6 +319,7 @@name = "Build Rust (ensu_uniffi)";outputPaths = ("$(TARGET_TEMP_DIR)/ensu_rust/libensu_uniffi.a",+ "$(TARGET_TEMP_DIR)/ensu_rust/libllmchat_db_uniffi.a",);runOnlyForDeploymentPostprocessing = 0;shellPath = /bin/sh;@@ -523,11 +525,14 @@"$(inherited)","-force_load","$(TARGET_TEMP_DIR)/ensu_rust/libensu_uniffi.a",+ "$(TARGET_TEMP_DIR)/ensu_rust/libllmchat_db_uniffi.a",);OTHER_SWIFT_FLAGS = ("$(inherited)","-Xcc","-fmodule-map-file=$(SRCROOT)/ensu/Generated/ensu_uniffiFFI.modulemap",+ "-Xcc",+ "-fmodule-map-file=$(SRCROOT)/ensu/Generated/llmchat_db_uniffiFFI.modulemap",);SWIFT_EMIT_LOC_STRINGS = YES;SWIFT_VERSION = 5.0;@@ -577,11 +582,14 @@"$(inherited)","-force_load","$(TARGET_TEMP_DIR)/ensu_rust/libensu_uniffi.a",+ "$(TARGET_TEMP_DIR)/ensu_rust/libllmchat_db_uniffi.a",);OTHER_SWIFT_FLAGS = ("$(inherited)","-Xcc","-fmodule-map-file=$(SRCROOT)/ensu/Generated/ensu_uniffiFFI.modulemap",+ "-Xcc",+ "-fmodule-map-file=$(SRCROOT)/ensu/Generated/llmchat_db_uniffiFFI.modulemap",);SWIFT_EMIT_LOC_STRINGS = YES;SWIFT_VERSION = 5.0;@@ -630,11 +638,14 @@"SystemConfiguration","-force_load","$(TARGET_TEMP_DIR)/ensu_rust/libensu_uniffi.a",+ "$(TARGET_TEMP_DIR)/ensu_rust/libllmchat_db_uniffi.a",);OTHER_SWIFT_FLAGS = ("$(inherited)","-Xcc","-fmodule-map-file=$(SRCROOT)/ensu/Generated/ensu_uniffiFFI.modulemap",+ "-Xcc",+ "-fmodule-map-file=$(SRCROOT)/ensu/Generated/llmchat_db_uniffiFFI.modulemap",);SDKROOT = macosx;SUPPORTED_PLATFORMS = macosx;@@ -684,11 +695,14 @@"SystemConfiguration","-force_load","$(TARGET_TEMP_DIR)/ensu_rust/libensu_uniffi.a",+ "$(TARGET_TEMP_DIR)/ensu_rust/libllmchat_db_uniffi.a",);OTHER_SWIFT_FLAGS = ("$(inherited)","-Xcc","-fmodule-map-file=$(SRCROOT)/ensu/Generated/ensu_uniffiFFI.modulemap",+ "-Xcc",+ "-fmodule-map-file=$(SRCROOT)/ensu/Generated/llmchat_db_uniffiFFI.modulemap",);SDKROOT = macosx;SUPPORTED_PLATFORMS = macosx;diff --git a/mobile/native/darwin/Apps/ensu/ensu/Chat/ChatViewModel.swift b/mobile/native/darwin/Apps/ensu/ensu/Chat/ChatViewModel.swiftindex f8dec76228..977bc3313f 100644--- a/mobile/native/darwin/Apps/ensu/ensu/Chat/ChatViewModel.swift+++ b/mobile/native/darwin/Apps/ensu/ensu/Chat/ChatViewModel.swift@@ -139,6 +139,8 @@ final class ChatViewModel: ObservableObject {@Published var downloadToast: DownloadToastState?private let provider: InferenceRsProvider+ private let chatDb: LlmChatDb+ private let attachmentsDir: URLprivate let modelSettings = ModelSettingsStore.sharedprivate var messageStore: [UUID: [MessageNode]] = [:]@@ -150,15 +152,79 @@ final class ChatViewModel: ObservableObject {private var activeGenerationSessionId: UUID?init() {- let session = ChatSession(title: "New chat", lastMessage: "", updatedAt: Date())- self.sessions = [session]- self.currentSessionId = session.id+ let baseDir = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first+ ?? FileManager.default.temporaryDirectory++ // LLM model files.+ let llmDir = baseDir.appendingPathComponent("llm", isDirectory: true)+ let provider = InferenceRsProvider(modelDir: llmDir)++ // Chat DB + attachments.+ let dbDir = baseDir.appendingPathComponent("llmchat", isDirectory: true)+ try? FileManager.default.createDirectory(at: dbDir, withIntermediateDirectories: true, attributes: nil)+ let attachmentsDir = dbDir.appendingPathComponent("chat_attachments", isDirectory: true)+ try? FileManager.default.createDirectory(at: attachmentsDir, withIntermediateDirectories: true, attributes: nil)++ let key = CredentialStore.shared.getOrCreateChatDbKey()+ let mainDbPath = dbDir.appendingPathComponent("llmchat.db").path+ let attachmentsDbPath = dbDir.appendingPathComponent("llmchat_attachments.db").path++ let chatDb: LlmChatDb+ do {+ chatDb = try LlmChatDb.open(mainDbPath: mainDbPath, attachmentsDbPath: attachmentsDbPath, key: key)+ } catch {+ fatalError("Failed to open chat DB: \(error)")+ }++ // Load sessions/messages.+ let loaded = (try? chatDb.listSessions()) ?? []+ var sessions: [ChatSession] = []++ if loaded.isEmpty {+ if let created = try? chatDb.createSession(title: "New chat"),+ let id = UUID(uuidString: created.uuid) {+ sessions = [ChatSession(+ id: id,+ title: created.title,+ lastMessage: "",+ updatedAt: Date(timeIntervalSince1970: Double(created.updatedAtUs) / 1_000_000.0)+ )]+ }+ } else {+ sessions = loaded.compactMap { session in+ guard let id = UUID(uuidString: session.uuid) else { return nil }+ let lastMessage = (try? chatDb.getMessages(sessionUuid: session.uuid))?.last?.text ?? ""+ return ChatSession(+ id: id,+ title: session.title,+ lastMessage: lastMessage,+ updatedAt: Date(timeIntervalSince1970: Double(session.updatedAtUs) / 1_000_000.0)+ )+ }+ }++ if sessions.isEmpty {+ sessions = [ChatSession(title: "New chat", lastMessage: "", updatedAt: Date())]+ }++ // Stored properties.+ self.provider = provider+ self.chatDb = chatDb+ self.attachmentsDir = attachmentsDir++ self.sessions = sessions+ self.currentSessionId = sessions.first?.idself.messages = []- self.messageStore[session.id] = []- self.branchSelections[session.id] = [:]- let baseDir = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first ?? FileManager.default.temporaryDirectory- self.provider = InferenceRsProvider(modelDir: baseDir.appendingPathComponent("llm", isDirectory: true))+ for session in sessions {+ self.messageStore[session.id] = []+ self.branchSelections[session.id] = [:]+ }++ if let current = self.currentSessionId {+ loadMessagesFromDb(for: current)+ rebuildMessages(for: current)+ }}var currentSession: ChatSession? {@@ -181,7 +247,11 @@ final class ChatViewModel: ObservableObject {draftAttachments = []editingMessageId = nil- let session = ChatSession(title: "New chat", lastMessage: "", updatedAt: Date())+ let created = (try? chatDb.createSession(title: "New chat"))+ let sessionId = created.flatMap { UUID(uuidString: $0.uuid) } ?? UUID()+ let updatedAt = created.map { Date(timeIntervalSince1970: Double($0.updatedAtUs) / 1_000_000.0) } ?? Date()++ let session = ChatSession(id: sessionId, title: created?.title ?? "New chat", lastMessage: "", updatedAt: updatedAt)sessions.insert(session, at: 0)currentSessionId = session.idmessageStore[session.id] = []@@ -201,6 +271,7 @@ final class ChatViewModel: ObservableObject {streamingParentId = nildownloadToast = nilcurrentSessionId = session.id+ loadMessagesFromDb(for: session.id)rebuildMessages(for: session.id)}@@ -217,12 +288,15 @@ final class ChatViewModel: ObservableObject {streamingParentId = nildownloadToast = nil}+ try? chatDb.deleteSession(uuid: session.id.uuidString)+sessions.removeAll { $0.id == session.id }messageStore[session.id] = nilbranchSelections[session.id] = nilif currentSessionId == session.id {currentSessionId = sessions.first?.idif let next = currentSessionId {+ loadMessagesFromDb(for: next)rebuildMessages(for: next)} else {messages = []@@ -250,9 +324,11 @@ final class ChatViewModel: ObservableObject {Task.detached { [weak self] inguard let self else { return }do {- let url = try self.writeAttachment(data: data, fileName: fileName ?? "photo.jpg")+ let id = UUID()+ let url = try self.writeAttachment(data: data, attachmentId: id)let attachment = ChatAttachment(- name: url.lastPathComponent,+ id: id,+ name: fileName ?? "photo.jpg",size: Int64(data.count),kind: .image,url: url,@@ -275,10 +351,12 @@ final class ChatViewModel: ObservableObject {Task.detached { [weak self] inguard let self else { return }do {- let storedUrl = try self.copyAttachment(from: url)+ let id = UUID()+ let storedUrl = try self.copyAttachment(from: url, attachmentId: id)let size = (try? FileManager.default.attributesOfItem(atPath: storedUrl.path)[.size] as? NSNumber)?.int64Value ?? 0let attachment = ChatAttachment(- name: storedUrl.lastPathComponent,+ id: id,+ name: url.lastPathComponent,size: size,kind: .document,url: storedUrl,@@ -304,7 +382,6 @@ final class ChatViewModel: ObservableObject {guard !trimmed.isEmpty || !attachments.isEmpty else { return }let sessionId = currentSessionId ?? createSessionForDraft()- let timestamp = Date()let parentId: UUID? = {if let editingId = editingMessageId {@@ -314,8 +391,29 @@ final class ChatViewModel: ObservableObject {return buildSelectedPath(for: sessionId).last?.id}()+ let meta: [AttachmentMeta] = attachments.map { attachment in+ AttachmentMeta(+ id: attachment.id.uuidString,+ kind: attachment.kind == .image ? .image : .document,+ size: attachment.size,+ name: attachment.name+ )+ }++ guard let inserted = try? chatDb.insertMessage(+ sessionUuid: sessionId.uuidString,+ sender: .selfUser,+ text: trimmed,+ parentMessageUuid: parentId?.uuidString,+ attachments: meta+ ), let messageId = UUID(uuidString: inserted.uuid) else {+ return+ }++ let timestamp = Date(timeIntervalSince1970: Double(inserted.createdAtUs) / 1_000_000.0)+let userNode = MessageNode(- id: UUID(),+ id: messageId,sessionId: sessionId,parentId: parentId,role: .user,@@ -401,7 +499,11 @@ final class ChatViewModel: ObservableObject {}private func createSessionForDraft() -> UUID {- let session = ChatSession(title: "New chat", lastMessage: "", updatedAt: Date())+ let created = (try? chatDb.createSession(title: "New chat"))+ let sessionId = created.flatMap { UUID(uuidString: $0.uuid) } ?? UUID()+ let updatedAt = created.map { Date(timeIntervalSince1970: Double($0.updatedAtUs) / 1_000_000.0) } ?? Date()++ let session = ChatSession(id: sessionId, title: created?.title ?? "New chat", lastMessage: "", updatedAt: updatedAt)sessions.insert(session, at: 0)currentSessionId = session.idmessageStore[session.id] = []@@ -499,21 +601,31 @@ final class ChatViewModel: ObservableObject {return Double(tokenCount) / (Double(totalTimeMs) / 1000.0)}()- let assistant = MessageNode(- id: UUID(),- sessionId: parent.sessionId,- parentId: parent.id,- role: .assistant,+ let meta: [AttachmentMeta] = []+ if let inserted = try? chatDb.insertMessage(+ sessionUuid: parent.sessionId.uuidString,+ sender: .other,text: trimmed,- timestamp: Date(),- attachments: [],- isInterrupted: interrupted,- tokensPerSecond: tokensPerSecond- )+ parentMessageUuid: parent.id.uuidString,+ attachments: meta+ ), let assistantId = UUID(uuidString: inserted.uuid) {+ let timestamp = Date(timeIntervalSince1970: Double(inserted.createdAtUs) / 1_000_000.0)+ let assistant = MessageNode(+ id: assistantId,+ sessionId: parent.sessionId,+ parentId: parent.id,+ role: .assistant,+ text: trimmed,+ timestamp: timestamp,+ attachments: [],+ isInterrupted: interrupted,+ tokensPerSecond: tokensPerSecond+ )- messageStore[parent.sessionId, default: []].append(assistant)- updateSelection(for: parent.sessionId, parentId: parent.id, childId: assistant.id)- updateSessionPreview(sessionId: parent.sessionId, preview: trimmed, date: assistant.timestamp)+ messageStore[parent.sessionId, default: []].append(assistant)+ updateSelection(for: parent.sessionId, parentId: parent.id, childId: assistant.id)+ updateSessionPreview(sessionId: parent.sessionId, preview: trimmed, date: assistant.timestamp)+ }}if activeGenerationId == generationId {@@ -563,6 +675,57 @@ final class ChatViewModel: ObservableObject {isDownloading = progress.percent >= 0 && progress.percent < 100}+ private func loadMessagesFromDb(for sessionId: UUID) {+ guard messageStore[sessionId] != nil else {+ messageStore[sessionId] = []+ branchSelections[sessionId] = [:]+ return+ }++ guard let rawMessages = try? chatDb.getMessages(sessionUuid: sessionId.uuidString) else {+ messageStore[sessionId] = []+ branchSelections[sessionId] = [:]+ return+ }++ let nodes: [MessageNode] = rawMessages.compactMap { msg in+ guard let messageId = UUID(uuidString: msg.uuid) else { return nil }+ let parentId = msg.parentMessageUuid.flatMap { UUID(uuidString: $0) }+ let role: ChatMessage.Role = (msg.sender == .selfUser) ? .user : .assistant+ let timestamp = Date(timeIntervalSince1970: Double(msg.createdAtUs) / 1_000_000.0)++ let attachments: [ChatAttachment] = msg.attachments.compactMap { meta in+ guard let attachmentId = UUID(uuidString: meta.id) else { return nil }+ let kind: ChatAttachment.Kind = (meta.kind == .image) ? .image : .document+ let url = attachmentsDir.appendingPathComponent(meta.id)+ return ChatAttachment(+ id: attachmentId,+ name: meta.name,+ size: meta.size,+ kind: kind,+ url: url,+ isUploading: false+ )+ }++ return MessageNode(+ id: messageId,+ sessionId: sessionId,+ parentId: parentId,+ role: role,+ text: msg.text,+ timestamp: timestamp,+ attachments: attachments,+ isInterrupted: false,+ tokensPerSecond: nil+ )+ }++ messageStore[sessionId] = nodes+ // Branch selection is computed in-memory.+ branchSelections[sessionId] = [:]+ }+private func rebuildMessages(for sessionId: UUID) {let path = buildSelectedPath(for: sessionId)let childrenMap = childrenByParent(sessionId: sessionId)@@ -686,24 +849,22 @@ final class ChatViewModel: ObservableObject {private nonisolated func attachmentsDirectory() throws -> URL {let base = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first?? FileManager.default.temporaryDirectory- let dir = base.appendingPathComponent("llm", isDirectory: true)- .appendingPathComponent("attachments", isDirectory: true)+ let dir = base.appendingPathComponent("llmchat", isDirectory: true)+ .appendingPathComponent("chat_attachments", isDirectory: true)try FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true, attributes: nil)return dir}- private nonisolated func writeAttachment(data: Data, fileName: String) throws -> URL {+ private nonisolated func writeAttachment(data: Data, attachmentId: UUID) throws -> URL {let dir = try attachmentsDirectory()- let safeName = fileName.replacingOccurrences(of: "/", with: "_")- let destination = dir.appendingPathComponent("\(UUID().uuidString)_\(safeName)")+ let destination = dir.appendingPathComponent(attachmentId.uuidString)try data.write(to: destination, options: .atomic)return destination}- private nonisolated func copyAttachment(from url: URL) throws -> URL {+ private nonisolated func copyAttachment(from url: URL, attachmentId: UUID) throws -> URL {let dir = try attachmentsDirectory()- let safeName = url.lastPathComponent.replacingOccurrences(of: "/", with: "_")- let destination = dir.appendingPathComponent("\(UUID().uuidString)_\(safeName)")+ let destination = dir.appendingPathComponent(attachmentId.uuidString)let needsSecurity = url.startAccessingSecurityScopedResource()defer {diff --git a/mobile/native/darwin/Apps/ensu/ensu/Services/CredentialStore.swift b/mobile/native/darwin/Apps/ensu/ensu/Services/CredentialStore.swiftindex b296fe7fd9..d297e61d6a 100644--- a/mobile/native/darwin/Apps/ensu/ensu/Services/CredentialStore.swift+++ b/mobile/native/darwin/Apps/ensu/ensu/Services/CredentialStore.swift@@ -1,4 +1,5 @@import Foundation+import Securityfinal class CredentialStore {static let shared = CredentialStore()@@ -16,6 +17,7 @@ final class CredentialStore {static let token = "ensu.token"static let masterKey = "ensu.masterKey"static let secretKey = "ensu.secretKey"+ static let chatDbKey = "ensu.chatDbKey"}var email: String? {@@ -60,6 +62,33 @@ final class CredentialStore {try KeychainStore.set(secretKey, service: keychainService, account: KeychainAccount.secretKey)}+ /// Returns a stable 32-byte key for encrypting the local chat DB.+ ///+ /// Rules:+ /// - If already stored, reuse it.+ /// - Else, if the account master key exists and is 32 bytes, pin it as the chat DB key.+ /// - Else, generate a random 32-byte key and persist it.+ func getOrCreateChatDbKey() -> Data {+ if let existing = try? KeychainStore.get(service: keychainService, account: KeychainAccount.chatDbKey), existing.count == 32 {+ return existing+ }++ if let master = try? KeychainStore.get(service: keychainService, account: KeychainAccount.masterKey), master.count == 32 {+ try? KeychainStore.set(master, service: keychainService, account: KeychainAccount.chatDbKey)+ return master+ }++ var bytes = [UInt8](repeating: 0, count: 32)+ let status = SecRandomCopyBytes(kSecRandomDefault, bytes.count, &bytes)+ if status != errSecSuccess {+ // Fallback to less ideal randomness if SecRandom fails (shouldn't happen on iOS).+ bytes = (0..<32).map { _ in UInt8.random(in: UInt8.min...UInt8.max) }+ }+ let data = Data(bytes)+ try? KeychainStore.set(data, service: keychainService, account: KeychainAccount.chatDbKey)+ return data+ }+func clear() {UserDefaults.standard.removeObject(forKey: DefaultsKey.email)UserDefaults.standard.removeObject(forKey: DefaultsKey.userId)@@ -67,5 +96,6 @@ final class CredentialStore {try? KeychainStore.delete(service: keychainService, account: KeychainAccount.token)try? KeychainStore.delete(service: keychainService, account: KeychainAccount.masterKey)try? KeychainStore.delete(service: keychainService, account: KeychainAccount.secretKey)+ // Note: keep chatDbKey to preserve local chats across sign-out.}}diff --git a/mobile/native/darwin/Apps/ensu/scripts/build-rust.sh b/mobile/native/darwin/Apps/ensu/scripts/build-rust.shindex 343cfe66f8..a8b693ceb4 100755--- a/mobile/native/darwin/Apps/ensu/scripts/build-rust.sh+++ b/mobile/native/darwin/Apps/ensu/scripts/build-rust.sh@@ -1,10 +1,11 @@#!/bin/shset -euo pipefail-# Build the UniFFI Rust static library for the current Xcode build platform.+# Build the UniFFI Rust static libraries for the current Xcode build platform.#-# Outputs a universal static library at:+# Outputs universal static libraries at:# $TARGET_TEMP_DIR/ensu_rust/libensu_uniffi.a+# $TARGET_TEMP_DIR/ensu_rust/libllmchat_db_uniffi.aif [ -z "${SRCROOT:-}" ] || [ -z "${TARGET_TEMP_DIR:-}" ] || [ -z "${PLATFORM_NAME:-}" ] || [ -z "${ARCHS:-}" ]; thenecho "Missing required Xcode environment variables (SRCROOT/TARGET_TEMP_DIR/PLATFORM_NAME/ARCHS)" >&2@@ -12,7 +13,6 @@ if [ -z "${SRCROOT:-}" ] || [ -z "${TARGET_TEMP_DIR:-}" ] || [ -z "${PLATFORM_NAfiREPO_ROOT="$(cd "${SRCROOT}/../../../../.." && pwd)"-CRATE_DIR="${REPO_ROOT}/rust/ensu_uniffi"OUT_DIR="${TARGET_TEMP_DIR}/ensu_rust"mkdir -p "${OUT_DIR}"@@ -94,62 +94,69 @@ HOST_SDKROOT="$(xcrun --sdk macosx --show-sdk-path)"# Ensure host builds (build scripts) use the macOS SDK.export SDKROOT="${HOST_SDKROOT}"-# Build per-arch and then lipo into a universal static library for this platform.-INPUT_LIBS=""+build_crate_universal() {+ crate_name="$1" # e.g. ensu_uniffi+ crate_dir="$2" # absolute path+ lib_name="$3" # e.g. libensu_uniffi.a-for arch in ${ARCHS}; do- target="$(rust_target_for "${PLATFORM_NAME}" "$arch")"- if [ -z "$target" ]; then- echo "Skipping unsupported arch/platform: ${PLATFORM_NAME} ${arch}" >&2- continue- fi+ echo "🔧 Building ${crate_name} → ${lib_name}"- # Ensure target is installed.- if ! rustup target list --installed | grep -q "^${target}$"; then- echo "Installing Rust target ${target}..."- rustup target add "${target}"- fi+ INPUT_LIBS=""- target_env="$(echo "${target}" | tr '[:lower:]-' '[:upper:]_')"+ for arch in ${ARCHS}; do+ target="$(rust_target_for "${PLATFORM_NAME}" "$arch")"+ if [ -z "$target" ]; then+ echo "Skipping unsupported arch/platform: ${PLATFORM_NAME} ${arch}" >&2+ continue+ fi- # Linker + sysroot for the target.- eval "export CARGO_TARGET_${target_env}_LINKER=\"${TARGET_CLANG}\""- eval "export CFLAGS_${target_env}=\"-isysroot ${TARGET_SDKROOT}\""- eval "export CXXFLAGS_${target_env}=\"-isysroot ${TARGET_SDKROOT}\""+ if ! rustup target list --installed | grep -q "^${target}$"; then+ echo "Installing Rust target ${target}..."+ rustup target add "${target}"+ fi- # Pass the SDK root to the linker explicitly (important when SDKROOT is macOS).- RUSTFLAGS_TARGET="${RUSTFLAGS:-} -C link-arg=-isysroot -C link-arg=${TARGET_SDKROOT}"- if [ "${PLATFORM_NAME}" = "iphonesimulator" ] && [ -n "${IPHONEOS_DEPLOYMENT_TARGET:-}" ]; then- RUSTFLAGS_TARGET="${RUSTFLAGS_TARGET} -C link-arg=-mios-simulator-version-min=${IPHONEOS_DEPLOYMENT_TARGET}"- elif [ "${PLATFORM_NAME}" = "iphoneos" ] && [ -n "${IPHONEOS_DEPLOYMENT_TARGET:-}" ]; then- RUSTFLAGS_TARGET="${RUSTFLAGS_TARGET} -C link-arg=-miphoneos-version-min=${IPHONEOS_DEPLOYMENT_TARGET}"- fi+ target_env="$(echo "${target}" | tr '[:lower:]-' '[:upper:]_')"- echo "Building ensu_uniffi for ${PLATFORM_NAME} ${arch} (${target}) [${PROFILE}]"- (cd "${CRATE_DIR}" && RUSTFLAGS="${RUSTFLAGS_TARGET}" cargo build ${CARGO_FLAGS} --target "${target}")+ eval "export CARGO_TARGET_${target_env}_LINKER=\"${TARGET_CLANG}\""+ eval "export CFLAGS_${target_env}=\"-isysroot ${TARGET_SDKROOT}\""+ eval "export CXXFLAGS_${target_env}=\"-isysroot ${TARGET_SDKROOT}\""- lib_path="${CRATE_DIR}/target/${target}/${PROFILE}/libensu_uniffi.a"- if [ ! -f "${lib_path}" ]; then- echo "Expected library not found: ${lib_path}" >&2- exit 1- fi+ RUSTFLAGS_TARGET="${RUSTFLAGS:-} -C link-arg=-isysroot -C link-arg=${TARGET_SDKROOT}"+ if [ "${PLATFORM_NAME}" = "iphonesimulator" ] && [ -n "${IPHONEOS_DEPLOYMENT_TARGET:-}" ]; then+ RUSTFLAGS_TARGET="${RUSTFLAGS_TARGET} -C link-arg=-mios-simulator-version-min=${IPHONEOS_DEPLOYMENT_TARGET}"+ elif [ "${PLATFORM_NAME}" = "iphoneos" ] && [ -n "${IPHONEOS_DEPLOYMENT_TARGET:-}" ]; then+ RUSTFLAGS_TARGET="${RUSTFLAGS_TARGET} -C link-arg=-miphoneos-version-min=${IPHONEOS_DEPLOYMENT_TARGET}"+ fi- arch_lib="${OUT_DIR}/libensu_uniffi_${arch}.a"- cp "${lib_path}" "${arch_lib}"- INPUT_LIBS="${INPUT_LIBS} ${arch_lib}"+ echo "Building ${crate_name} for ${PLATFORM_NAME} ${arch} (${target}) [${PROFILE}]"+ (cd "${crate_dir}" && RUSTFLAGS="${RUSTFLAGS_TARGET}" cargo build ${CARGO_FLAGS} --target "${target}")-done+ lib_path="${crate_dir}/target/${target}/${PROFILE}/${lib_name}"+ if [ ! -f "${lib_path}" ]; then+ echo "Expected library not found: ${lib_path}" >&2+ exit 1+ fi-# Create universal lib.-UNIVERSAL_LIB="${OUT_DIR}/libensu_uniffi.a"-rm -f "${UNIVERSAL_LIB}"+ arch_lib="${OUT_DIR}/${lib_name%.a}_${arch}.a"+ cp "${lib_path}" "${arch_lib}"+ INPUT_LIBS="${INPUT_LIBS} ${arch_lib}"+ done-# If we have only one arch, just copy.-set -- ${INPUT_LIBS}-if [ "$#" -eq 1 ]; then- cp "$1" "${UNIVERSAL_LIB}"-else- lipo -create ${INPUT_LIBS} -output "${UNIVERSAL_LIB}"-fi+ universal_lib="${OUT_DIR}/${lib_name}"+ rm -f "${universal_lib}"++ set -- ${INPUT_LIBS}+ if [ "$#" -eq 0 ]; then+ echo "No supported architectures found for ${crate_name} (${PLATFORM_NAME} ${ARCHS})" >&2+ exit 1+ elif [ "$#" -eq 1 ]; then+ cp "$1" "${universal_lib}"+ else+ lipo -create ${INPUT_LIBS} -output "${universal_lib}"+ fi++ echo "✅ Built ${universal_lib}"+}-echo "✅ Built ${UNIVERSAL_LIB}"+build_crate_universal "ensu_uniffi" "${REPO_ROOT}/rust/ensu_uniffi" "libensu_uniffi.a"+build_crate_universal "llmchat_db_uniffi" "${REPO_ROOT}/rust/llmchat_db_uniffi" "libllmchat_db_uniffi.a"diff --git a/rust/llmchat-db/src/attachments_db.rs b/rust/llmchat-db/src/attachments_db.rsnew file mode 100644index 0000000000..2ab4a90e07--- /dev/null+++ b/rust/llmchat-db/src/attachments_db.rs@@ -0,0 +1,267 @@+use std::sync::Arc;++use uuid::Uuid;++use crate::backend::{Backend, RowExt, Value};+use crate::traits::{Clock, SystemClock};+use crate::{Result};++#[derive(Debug, Clone, Copy, PartialEq, Eq)]+pub enum UploadState {+ Pending,+ Uploading,+ Uploaded,+ Failed,+}++impl UploadState {+ pub fn as_str(&self) -> &'static str {+ match self {+ UploadState::Pending => "pending",+ UploadState::Uploading => "uploading",+ UploadState::Uploaded => "uploaded",+ UploadState::Failed => "failed",+ }+ }+}++impl std::str::FromStr for UploadState {+ type Err = crate::Error;++ fn from_str(value: &str) -> std::result::Result<Self, Self::Err> {+ match value {+ "pending" => Ok(UploadState::Pending),+ "uploading" => Ok(UploadState::Uploading),+ "uploaded" => Ok(UploadState::Uploaded),+ "failed" => Ok(UploadState::Failed),+ _ => Err(crate::Error::Row(format!(+ "invalid upload_state value {value}"+ ))),+ }+ }+}++#[derive(Debug, Clone, PartialEq, Eq)]+pub struct AttachmentUploadRow {+ pub attachment_id: String,+ pub session_uuid: Uuid,+ pub message_uuid: Uuid,+ pub size: i64,+ pub upload_state: UploadState,+ pub uploaded_at: Option<i64>,+ pub updated_at: i64,+}++pub struct AttachmentsDb<B: Backend> {+ backend: B,+ clock: Arc<dyn Clock>,+}++impl<B: Backend> AttachmentsDb<B> {+ pub fn new(backend: B, clock: Arc<dyn Clock>) -> Result<Self> {+ crate::attachments_migrations::migrate(&backend)?;+ Ok(Self { backend, clock })+ }++ pub fn new_with_defaults(backend: B) -> Result<Self> {+ Self::new(backend, Arc::new(SystemClock))+ }++ pub fn upsert_pending_attachment(+ &self,+ attachment_id: &str,+ session_uuid: Uuid,+ message_uuid: Uuid,+ size: i64,+ ) -> Result<()> {+ let now = self.clock.now_us();+ // If row exists, do not overwrite an existing terminal state.+ // Only ensure it's present and updated.+ self.backend.execute(+ "INSERT INTO attachments (attachment_id, session_uuid, message_uuid, size, upload_state, uploaded_at, updated_at) \+ VALUES (?, ?, ?, ?, 'pending', NULL, ?) \+ ON CONFLICT(attachment_id) DO UPDATE SET \+ session_uuid = excluded.session_uuid, \+ message_uuid = excluded.message_uuid, \+ size = excluded.size, \+ updated_at = excluded.updated_at",+ &[+ Value::Text(attachment_id.to_string()),+ Value::Text(session_uuid.to_string()),+ Value::Text(message_uuid.to_string()),+ Value::Integer(size),+ Value::Integer(now),+ ],+ )?;+ Ok(())+ }++ pub fn set_attachment_upload_state(+ &self,+ attachment_id: &str,+ state: UploadState,+ ) -> Result<()> {+ let now = self.clock.now_us();+ self.backend.execute(+ "UPDATE attachments SET upload_state = ?, updated_at = ? WHERE attachment_id = ?",+ &[+ Value::Text(state.as_str().to_string()),+ Value::Integer(now),+ Value::Text(attachment_id.to_string()),+ ],+ )?;+ Ok(())+ }++ pub fn mark_attachment_uploaded(&self, attachment_id: &str) -> Result<()> {+ let now = self.clock.now_us();+ self.backend.execute(+ "UPDATE attachments SET upload_state = 'uploaded', uploaded_at = ?, updated_at = ? WHERE attachment_id = ?",+ &[+ Value::Integer(now),+ Value::Integer(now),+ Value::Text(attachment_id.to_string()),+ ],+ )?;+ Ok(())+ }++ pub fn get_pending_uploads_for_session(+ &self,+ session_uuid: Uuid,+ ) -> Result<Vec<AttachmentUploadRow>> {+ let rows = self.backend.query(+ "SELECT attachment_id, session_uuid, message_uuid, size, upload_state, uploaded_at, updated_at \+ FROM attachments \+ WHERE session_uuid = ? AND upload_state IN ('pending','uploading','failed') \+ ORDER BY updated_at ASC",+ &[Value::Text(session_uuid.to_string())],+ )?;++ rows.iter().map(Self::row_from_row).collect()+ }++ pub fn get_pending_uploads_for_message(+ &self,+ message_uuid: Uuid,+ ) -> Result<Vec<AttachmentUploadRow>> {+ let rows = self.backend.query(+ "SELECT attachment_id, session_uuid, message_uuid, size, upload_state, uploaded_at, updated_at \+ FROM attachments \+ WHERE message_uuid = ? AND upload_state IN ('pending','uploading','failed') \+ ORDER BY updated_at ASC",+ &[Value::Text(message_uuid.to_string())],+ )?;++ rows.iter().map(Self::row_from_row).collect()+ }++ pub fn delete_attachment_tracking_for_message(&self, message_uuid: Uuid) -> Result<()> {+ self.backend.execute(+ "DELETE FROM attachments WHERE message_uuid = ?",+ &[Value::Text(message_uuid.to_string())],+ )?;+ Ok(())+ }++ pub fn delete_attachment_tracking_for_session(&self, session_uuid: Uuid) -> Result<()> {+ self.backend.execute(+ "DELETE FROM attachments WHERE session_uuid = ?",+ &[Value::Text(session_uuid.to_string())],+ )?;+ Ok(())+ }++ fn row_from_row(row: &crate::backend::Row) -> Result<AttachmentUploadRow> {+ let attachment_id = row.get_string(0)?;+ let session_uuid = Uuid::parse_str(&row.get_string(1)?)?;+ let message_uuid = Uuid::parse_str(&row.get_string(2)?)?;+ let size = row.get_i64(3)?;+ let upload_state: UploadState = row.get_string(4)?.parse()?;+ let uploaded_at = row.get_optional_i64(5)?;+ let updated_at = row.get_i64(6)?;+ Ok(AttachmentUploadRow {+ attachment_id,+ session_uuid,+ message_uuid,+ size,+ upload_state,+ uploaded_at,+ updated_at,+ })+ }+}++#[cfg(feature = "sqlite")]+impl AttachmentsDb<crate::backend::sqlite::SqliteBackend> {+ pub fn open_sqlite(+ path: impl AsRef<std::path::Path>,+ clock: Arc<dyn Clock>,+ ) -> Result<Self> {+ let backend = crate::backend::sqlite::SqliteBackend::open(path)?;+ Self::new(backend, clock)+ }++ pub fn open_sqlite_with_defaults(path: impl AsRef<std::path::Path>) -> Result<Self> {+ let backend = crate::backend::sqlite::SqliteBackend::open(path)?;+ Self::new_with_defaults(backend)+ }++ pub fn open_in_memory(clock: Arc<dyn Clock>) -> Result<Self> {+ let backend = crate::backend::sqlite::SqliteBackend::open_in_memory()?;+ Self::new(backend, clock)+ }+}++#[cfg(all(test, feature = "sqlite"))]+mod tests {+ use std::sync::atomic::{AtomicI64, Ordering};++ use super::*;+ use crate::backend::sqlite::SqliteBackend;++ #[derive(Debug)]+ struct StepClock {+ current: AtomicI64,+ }++ impl StepClock {+ fn new(start: i64) -> Self {+ Self {+ current: AtomicI64::new(start),+ }+ }+ }++ impl Clock for StepClock {+ fn now_us(&self) -> i64 {+ self.current.fetch_add(1, Ordering::SeqCst)+ }+ }++ #[test]+ fn pending_and_mark_uploaded() {+ let clock = Arc::new(StepClock::new(100));+ let backend = SqliteBackend::open_in_memory().unwrap();+ let db = AttachmentsDb::new(backend, clock.clone()).unwrap();++ let session = Uuid::from_u128(1);+ let message = Uuid::from_u128(2);++ db.upsert_pending_attachment("att-1", session, message, 123)+ .unwrap();++ let pending = db.get_pending_uploads_for_session(session).unwrap();+ assert_eq!(pending.len(), 1);+ assert_eq!(pending[0].upload_state, UploadState::Pending);++ db.set_attachment_upload_state("att-1", UploadState::Uploading)+ .unwrap();+ let pending = db.get_pending_uploads_for_message(message).unwrap();+ assert_eq!(pending[0].upload_state, UploadState::Uploading);++ db.mark_attachment_uploaded("att-1").unwrap();+ let pending_after = db.get_pending_uploads_for_session(session).unwrap();+ assert!(pending_after.is_empty());+ }+}diff --git a/rust/llmchat-db/src/attachments_migrations.rs b/rust/llmchat-db/src/attachments_migrations.rsnew file mode 100644index 0000000000..ae6d3e0b0c--- /dev/null+++ b/rust/llmchat-db/src/attachments_migrations.rs@@ -0,0 +1,66 @@+use crate::{Backend, Error, Result};+use crate::backend::RowExt;+use crate::attachments_schema;++pub const LATEST_VERSION: i64 = 1;++pub fn migrate<B: Backend>(backend: &B) -> Result<()> {+ let version = user_version(backend)?;+ match version {+ 0 => {+ backend.execute_batch(attachments_schema::CREATE_ALL)?;+ backend.execute("PRAGMA user_version = 1;", &[])?;+ Ok(())+ }+ LATEST_VERSION => Ok(()),+ other => Err(Error::Migration(format!(+ "unsupported attachments schema version {other}"+ ))),+ }+}++fn user_version<B: Backend>(backend: &B) -> Result<i64> {+ let row = backend+ .query_row("PRAGMA user_version;", &[])?+ .ok_or_else(|| Error::Migration("missing user_version pragma".to_string()))?;+ row.get_i64(0)+}++#[cfg(all(test, feature = "sqlite"))]+mod tests {+ use super::*;+ use crate::backend::{BackendTx, RowExt, Value};+ use crate::backend::sqlite::SqliteBackend;++ #[test]+ fn creates_schema_and_indexes() {+ let backend = SqliteBackend::open_in_memory().unwrap();+ migrate(&backend).unwrap();++ let row = backend+ .query_row(+ "SELECT name FROM sqlite_master WHERE type = 'table' AND name = ?",+ &[Value::Text("attachments".to_string())],+ )+ .unwrap();+ assert!(row.is_some(), "missing attachments table");++ for index in [+ "idx_attachments_session",+ "idx_attachments_message",+ "idx_attachments_state",+ ] {+ let row = backend+ .query_row(+ "SELECT name FROM sqlite_master WHERE type = 'index' AND name = ?",+ &[Value::Text(index.to_string())],+ )+ .unwrap();+ assert!(row.is_some(), "missing index {index}");+ }++ let row = backend.query_row("PRAGMA user_version;", &[]).unwrap();+ let version = row.unwrap().get_i64(0).unwrap();+ assert_eq!(version, LATEST_VERSION);+ }+}diff --git a/rust/llmchat-db/src/attachments_schema.rs b/rust/llmchat-db/src/attachments_schema.rsnew file mode 100644index 0000000000..f4a255c7c2--- /dev/null+++ b/rust/llmchat-db/src/attachments_schema.rs@@ -0,0 +1,33 @@+pub const CREATE_ATTACHMENTS: &str = "+CREATE TABLE IF NOT EXISTS attachments (+ attachment_id TEXT PRIMARY KEY NOT NULL,+ session_uuid TEXT NOT NULL,+ message_uuid TEXT NOT NULL,+ size INTEGER NOT NULL,+ upload_state TEXT NOT NULL CHECK(upload_state IN ('pending','uploading','uploaded','failed')),+ uploaded_at INTEGER,+ updated_at INTEGER NOT NULL+);+";++pub const CREATE_INDEXES: &str = "+CREATE INDEX IF NOT EXISTS idx_attachments_session ON attachments(session_uuid);+CREATE INDEX IF NOT EXISTS idx_attachments_message ON attachments(message_uuid);+CREATE INDEX IF NOT EXISTS idx_attachments_state ON attachments(upload_state);+";++pub const CREATE_ALL: &str = "+CREATE TABLE IF NOT EXISTS attachments (+ attachment_id TEXT PRIMARY KEY NOT NULL,+ session_uuid TEXT NOT NULL,+ message_uuid TEXT NOT NULL,+ size INTEGER NOT NULL,+ upload_state TEXT NOT NULL CHECK(upload_state IN ('pending','uploading','uploaded','failed')),+ uploaded_at INTEGER,+ updated_at INTEGER NOT NULL+);++CREATE INDEX IF NOT EXISTS idx_attachments_session ON attachments(session_uuid);+CREATE INDEX IF NOT EXISTS idx_attachments_message ON attachments(message_uuid);+CREATE INDEX IF NOT EXISTS idx_attachments_state ON attachments(upload_state);+";diff --git a/rust/llmchat-db/src/db.rs b/rust/llmchat-db/src/db.rsindex c182ad37cf..1e8ccb1266 100644--- a/rust/llmchat-db/src/db.rs+++ b/rust/llmchat-db/src/db.rs@@ -6,7 +6,7 @@ use zeroize::Zeroizing;use crate::backend::{Backend, BackendTx, RowExt, Value};use crate::crypto;use crate::migrations;-use crate::models::{Attachment, EntityType, Message, Sender, Session, StoredAttachment};+use crate::models::{AttachmentMeta, EntityType, Message, Sender, Session, StoredAttachment};use crate::traits::{Clock, RandomUuidGen, SystemClock, UuidGen};use crate::{Error, Result};@@ -141,7 +141,7 @@ impl<B: Backend> ChatDb<B> {sender: &str,text: &str,parent: Option<Uuid>,- attachments: Vec<Attachment>,+ attachments: Vec<AttachmentMeta>,) -> Result<Message> {let sender: Sender = sender.parse()?;let now = self.clock.now_us();@@ -240,69 +240,6 @@ impl<B: Backend> ChatDb<B> {})}- pub fn mark_attachment_uploaded(&self, message_uuid: Uuid, attachment_id: &str) -> Result<()> {- let now = self.clock.now_us();- let row = self.backend.query_row(- "SELECT attachments FROM messages WHERE message_uuid = ? AND deleted_at IS NULL",- &[Value::Text(message_uuid.to_string())],- )?;- let row = row.ok_or(Error::NotFound {- entity: EntityType::Message,- id: message_uuid,- })?;-- let attachments_json = row.get_optional_string(0)?;- let mut stored = parse_stored_attachments(attachments_json)?;- let mut found = false;- for attachment in &mut stored {- if attachment.id == attachment_id {- if attachment.uploaded_at.is_none() {- attachment.uploaded_at = Some(now);- }- found = true;- break;- }- }-- if !found {- return Err(Error::AttachmentNotFound(attachment_id.to_string()));- }-- let updated_json = if stored.is_empty() {- None- } else {- Some(serde_json::to_string(&stored)?)- };-- self.backend.execute(- "UPDATE messages SET attachments = ? WHERE message_uuid = ?",- &[- updated_json.map(Value::Text).unwrap_or(Value::Null),- Value::Text(message_uuid.to_string()),- ],- )?;-- Ok(())- }-- pub fn get_pending_uploads(&self, session_uuid: Uuid) -> Result<Vec<Attachment>> {- let rows = self.backend.query(- "SELECT attachments FROM messages WHERE session_uuid = ? AND deleted_at IS NULL",- &[Value::Text(session_uuid.to_string())],- )?;-- let mut pending = Vec::new();- for row in rows {- let attachments_json = row.get_optional_string(0)?;- let stored = parse_stored_attachments(attachments_json)?;- for attachment in stored.into_iter().filter(|att| att.uploaded_at.is_none()) {- pending.push(self.stored_to_attachment(attachment)?);- }- }-- Ok(pending)- }-pub fn mark_session_synced(&self, uuid: Uuid, remote_id: &str) -> Result<()> {let affected = self.backend.execute("UPDATE sessions SET remote_id = ?, needs_sync = 0 WHERE session_uuid = ?",@@ -410,7 +347,7 @@ impl<B: Backend> ChatDb<B> {})}- fn serialize_attachments(&self, attachments: &[Attachment]) -> Result<Option<String>> {+ fn serialize_attachments(&self, attachments: &[AttachmentMeta]) -> Result<Option<String>> {if attachments.is_empty() {return Ok(None);}@@ -421,7 +358,7 @@ impl<B: Backend> ChatDb<B> {Ok(Some(serde_json::to_string(&stored)?))}- fn deserialize_attachments(&self, raw: Option<String>) -> Result<Vec<Attachment>> {+ fn deserialize_attachments(&self, raw: Option<String>) -> Result<Vec<AttachmentMeta>> {let stored = parse_stored_attachments(raw)?;stored.into_iter()@@ -429,23 +366,21 @@ impl<B: Backend> ChatDb<B> {.collect()}- fn attachment_to_stored(&self, attachment: &Attachment) -> Result<StoredAttachment> {+ fn attachment_to_stored(&self, attachment: &AttachmentMeta) -> Result<StoredAttachment> {Ok(StoredAttachment {id: attachment.id.clone(),kind: attachment.kind,size: attachment.size,encrypted_name: crypto::encrypt_json_field(&attachment.name, &self.key)?,- uploaded_at: attachment.uploaded_at,})}- fn stored_to_attachment(&self, attachment: StoredAttachment) -> Result<Attachment> {- Ok(Attachment {+ fn stored_to_attachment(&self, attachment: StoredAttachment) -> Result<AttachmentMeta> {+ Ok(AttachmentMeta {id: attachment.id,kind: attachment.kind,size: attachment.size,name: crypto::decrypt_json_field(&attachment.encrypted_name, &self.key)?,- uploaded_at: attachment.uploaded_at,})}@@ -536,7 +471,7 @@ mod tests {use crate::backend::{BackendTx, RowExt, Value};use crate::backend::sqlite::SqliteBackend;use crate::crypto::KEY_BYTES;- use crate::models::{Attachment, AttachmentKind};+ use crate::models::{AttachmentMeta, AttachmentKind};#[derive(Debug)]struct StepClock {@@ -669,7 +604,7 @@ mod tests {}#[test]- fn attachment_upload_flow_does_not_touch_session() {+ fn attachment_metadata_is_encrypted_in_json() {let session_id = Uuid::from_u128(6);let message_id = Uuid::from_u128(7);let clock = Arc::new(StepClock::new(50, 1));@@ -678,37 +613,23 @@ mod tests {db.create_session("title").unwrap();let attachments = vec![- Attachment {+ AttachmentMeta {id: "att-1".to_string(),kind: AttachmentKind::Image,size: 123,name: "photo.jpg".to_string(),- uploaded_at: None,},- Attachment {+ AttachmentMeta {id: "att-2".to_string(),kind: AttachmentKind::Document,size: 456,name: "doc.pdf".to_string(),- uploaded_at: None,},];db.insert_message(session_id, "self", "hello", None, attachments).unwrap();- let updated_at_before = db.get_session(session_id).unwrap().unwrap().updated_at;-- let pending = db.get_pending_uploads(session_id).unwrap();- assert_eq!(pending.len(), 2);-- db.mark_attachment_uploaded(message_id, "att-1").unwrap();- let pending_after = db.get_pending_uploads(session_id).unwrap();- assert_eq!(pending_after.len(), 1);-- let updated_at_after = db.get_session(session_id).unwrap().unwrap().updated_at;- assert_eq!(updated_at_before, updated_at_after);-let row = db.backend.query_row(@@ -719,6 +640,7 @@ mod tests {.unwrap();let json = row.get_optional_string(0).unwrap().unwrap();let stored: Vec<StoredAttachment> = serde_json::from_str(&json).unwrap();+ assert_eq!(stored.len(), 2);assert!(stored[0].encrypted_name.starts_with("enc:v1:"));assert!(!stored[0].encrypted_name.contains("photo.jpg"));}diff --git a/rust/llmchat-db/src/error.rs b/rust/llmchat-db/src/error.rsindex a7a5f94dee..15604244e6 100644--- a/rust/llmchat-db/src/error.rs+++ b/rust/llmchat-db/src/error.rs@@ -27,8 +27,6 @@ pub enum Error {#[error("{entity:?} not found: {id}")]NotFound { entity: EntityType, id: uuid::Uuid },- #[error("attachment not found: {0}")]- AttachmentNotFound(String),#[error(transparent)]Crypto(#[from] ente_core::crypto::CryptoError),diff --git a/rust/llmchat-db/src/lib.rs b/rust/llmchat-db/src/lib.rsindex c2661eabfd..d3cbb61ae3 100644--- a/rust/llmchat-db/src/lib.rs+++ b/rust/llmchat-db/src/lib.rs@@ -3,17 +3,23 @@pub mod backend;pub mod crypto;pub mod db;+pub mod attachments_db;+pub mod attachments_migrations;+pub mod attachments_schema;pub mod error;pub mod migrations;pub mod models;pub mod schema;pub mod traits;+pub mod llmchat;pub use crate::backend::{Backend, BackendTx, Row, Value};pub use crate::db::ChatDb;+pub use crate::attachments_db::{AttachmentsDb, AttachmentUploadRow, UploadState};+pub use crate::llmchat::LlmChatDb;pub use crate::error::{Error, Result};pub use crate::models::{- Attachment, AttachmentKind, EntityType, Message, Sender, Session,+ AttachmentKind, AttachmentMeta, EntityType, Message, Sender, Session,};pub use crate::traits::{AttachmentStore, Clock, FileMetaStore, FsAttachmentStore, MetaStore, RandomUuidGen,diff --git a/rust/llmchat-db/src/llmchat.rs b/rust/llmchat-db/src/llmchat.rsnew file mode 100644index 0000000000..371967e529--- /dev/null+++ b/rust/llmchat-db/src/llmchat.rs@@ -0,0 +1,166 @@+use std::sync::Arc;++use uuid::Uuid;++use crate::attachments_db::{AttachmentUploadRow, AttachmentsDb, UploadState};+use crate::db::ChatDb;+use crate::models::{AttachmentMeta, EntityType, Message, Session};+use crate::traits::{Clock, UuidGen};+use crate::Result;++/// High-level DB that ties together the main chat DB and the attachments upload-state DB.+pub struct LlmChatDb<B: crate::Backend> {+ pub chat: ChatDb<B>,+ pub attachments: AttachmentsDb<B>,+}++impl<B: crate::Backend> LlmChatDb<B> {+ pub fn new(chat: ChatDb<B>, attachments: AttachmentsDb<B>) -> Self {+ Self { chat, attachments }+ }++ pub fn create_session(&self, title: &str) -> Result<Session> {+ self.chat.create_session(title)+ }++ pub fn get_session(&self, uuid: Uuid) -> Result<Option<Session>> {+ self.chat.get_session(uuid)+ }++ pub fn list_sessions(&self) -> Result<Vec<Session>> {+ self.chat.list_sessions()+ }++ pub fn update_session_title(&self, uuid: Uuid, title: &str) -> Result<()> {+ self.chat.update_session_title(uuid, title)+ }++ pub fn delete_session(&self, uuid: Uuid) -> Result<()> {+ // Best-effort cleanup in attachments DB. If this fails, still delete session.+ let _ = self.attachments.delete_attachment_tracking_for_session(uuid);+ self.chat.delete_session(uuid)+ }++ pub fn insert_message(+ &self,+ session_uuid: Uuid,+ sender: &str,+ text: &str,+ parent: Option<Uuid>,+ attachments: Vec<AttachmentMeta>,+ ) -> Result<Message> {+ let message = self+ .chat+ .insert_message(session_uuid, sender, text, parent, attachments.clone())?;++ for attachment in attachments {+ self.attachments.upsert_pending_attachment(+ &attachment.id,+ session_uuid,+ message.uuid,+ attachment.size,+ )?;+ }++ Ok(message)+ }++ pub fn get_messages(&self, session_uuid: Uuid) -> Result<Vec<Message>> {+ self.chat.get_messages(session_uuid)+ }++ pub fn update_message_text(&self, uuid: Uuid, text: &str) -> Result<()> {+ self.chat.update_message_text(uuid, text)+ }++ pub fn delete_message(&self, uuid: Uuid) -> Result<()> {+ let _ = self.attachments.delete_attachment_tracking_for_message(uuid);+ self.chat.delete_message(uuid)+ }++ // Attachments DB APIs+ pub fn upsert_pending_attachment(+ &self,+ attachment_id: &str,+ session_uuid: Uuid,+ message_uuid: Uuid,+ size: i64,+ ) -> Result<()> {+ self.attachments+ .upsert_pending_attachment(attachment_id, session_uuid, message_uuid, size)+ }++ pub fn set_attachment_upload_state(&self, attachment_id: &str, state: UploadState) -> Result<()> {+ self.attachments.set_attachment_upload_state(attachment_id, state)+ }++ pub fn mark_attachment_uploaded(&self, attachment_id: &str) -> Result<()> {+ self.attachments.mark_attachment_uploaded(attachment_id)+ }++ pub fn get_pending_uploads_for_session(+ &self,+ session_uuid: Uuid,+ ) -> Result<Vec<AttachmentUploadRow>> {+ self.attachments.get_pending_uploads_for_session(session_uuid)+ }++ pub fn get_pending_uploads_for_message(+ &self,+ message_uuid: Uuid,+ ) -> Result<Vec<AttachmentUploadRow>> {+ self.attachments.get_pending_uploads_for_message(message_uuid)+ }++ pub fn delete_attachment_tracking_for_message(&self, message_uuid: Uuid) -> Result<()> {+ self.attachments+ .delete_attachment_tracking_for_message(message_uuid)+ }++ pub fn delete_attachment_tracking_for_session(&self, session_uuid: Uuid) -> Result<()> {+ self.attachments+ .delete_attachment_tracking_for_session(session_uuid)+ }++ // Sync helpers+ pub fn mark_session_synced(&self, uuid: Uuid, remote_id: &str) -> Result<()> {+ self.chat.mark_session_synced(uuid, remote_id)+ }++ pub fn get_sessions_needing_sync(&self) -> Result<Vec<Session>> {+ self.chat.get_sessions_needing_sync()+ }++ pub fn get_pending_deletions(&self) -> Result<Vec<(EntityType, Uuid)>> {+ self.chat.get_pending_deletions()+ }++ pub fn hard_delete(&self, entity_type: EntityType, uuid: Uuid) -> Result<()> {+ self.chat.hard_delete(entity_type, uuid)+ }+}++#[cfg(feature = "sqlite")]+impl LlmChatDb<crate::backend::sqlite::SqliteBackend> {+ pub fn open_sqlite(+ main_path: impl AsRef<std::path::Path>,+ attachments_path: impl AsRef<std::path::Path>,+ key: Vec<u8>,+ clock: Arc<dyn Clock>,+ uuid_gen: Arc<dyn UuidGen>,+ ) -> Result<Self> {+ let chat = ChatDb::open_sqlite(main_path, key, clock.clone(), uuid_gen)?;+ let attachments = AttachmentsDb::open_sqlite(attachments_path, clock)?;+ Ok(Self { chat, attachments })+ }++ pub fn open_sqlite_with_defaults(+ main_path: impl AsRef<std::path::Path>,+ attachments_path: impl AsRef<std::path::Path>,+ key: Vec<u8>,+ ) -> Result<Self> {+ let chat = ChatDb::open_sqlite_with_defaults(main_path, key)?;+ let attachments = AttachmentsDb::open_sqlite_with_defaults(attachments_path)?;+ Ok(Self { chat, attachments })+ }+}diff --git a/rust/llmchat-db/src/models.rs b/rust/llmchat-db/src/models.rsindex 7ab7962865..3842545a68 100644--- a/rust/llmchat-db/src/models.rs+++ b/rust/llmchat-db/src/models.rs@@ -19,24 +19,17 @@ pub struct Message {pub parent_message_uuid: Option<Uuid>,pub sender: Sender,pub text: String,- pub attachments: Vec<Attachment>,+ pub attachments: Vec<AttachmentMeta>,pub created_at: i64,pub deleted_at: Option<i64>,}#[derive(Debug, Clone, PartialEq, Eq)]-pub struct Attachment {+pub struct AttachmentMeta {pub id: String,pub kind: AttachmentKind,pub size: i64,pub name: String,- pub uploaded_at: Option<i64>,-}--impl Attachment {- pub fn needs_upload(&self) -> bool {- self.uploaded_at.is_none()- }}#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]@@ -85,6 +78,4 @@ pub(crate) struct StoredAttachment {pub kind: AttachmentKind,pub size: i64,pub encrypted_name: String,- #[serde(skip_serializing_if = "Option::is_none")]- pub uploaded_at: Option<i64>,}diff --git a/rust/llmchat_db_uniffi/Cargo.lock b/rust/llmchat_db_uniffi/Cargo.locknew file mode 100644index 0000000000..f4321a513a--- /dev/null+++ b/rust/llmchat_db_uniffi/Cargo.lock@@ -0,0 +1,2501 @@+# This file is automatically @generated by Cargo.+# It is not intended for manual editing.+version = 4++[[package]]+name = "aead"+version = "0.5.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "d122413f284cf2d62fb1b7db97e02edb8cda96d769b16e443a4f6195e35662b0"+dependencies = [+ "crypto-common",+ "generic-array",+]++[[package]]+name = "anyhow"+version = "1.0.100"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "a23eb6b1614318a8071c9b2521f36b424b2c83db5eb3a0fead4a6c0809af6e61"++[[package]]+name = "argon2"+version = "0.5.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "3c3610892ee6e0cbce8ae2700349fcf8f98adb0dbfbee85aec3c9179d29cc072"+dependencies = [+ "base64ct",+ "blake2",+ "cpufeatures",+ "password-hash",+]++[[package]]+name = "arrayref"+version = "0.3.9"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "76a2e8124351fda1ef8aaaa3bbd7ebbcb486bbcd4225aca0aa0d84bb2db8fecb"++[[package]]+name = "arrayvec"+version = "0.7.6"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50"++[[package]]+name = "askama"+version = "0.14.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "f75363874b771be265f4ffe307ca705ef6f3baa19011c149da8674a87f1b75c4"+dependencies = [+ "askama_derive",+ "itoa",+ "percent-encoding",+ "serde",+ "serde_json",+]++[[package]]+name = "askama_derive"+version = "0.14.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "129397200fe83088e8a68407a8e2b1f826cf0086b21ccdb866a722c8bcd3a94f"+dependencies = [+ "askama_parser",+ "basic-toml",+ "memchr",+ "proc-macro2",+ "quote",+ "rustc-hash",+ "serde",+ "serde_derive",+ "syn",+]++[[package]]+name = "askama_parser"+version = "0.14.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "d6ab5630b3d5eaf232620167977f95eb51f3432fc76852328774afbd242d4358"+dependencies = [+ "memchr",+ "serde",+ "serde_derive",+ "winnow",+]++[[package]]+name = "atomic-waker"+version = "1.1.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0"++[[package]]+name = "autocfg"+version = "1.5.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"++[[package]]+name = "base64"+version = "0.22.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"++[[package]]+name = "base64ct"+version = "1.8.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "2af50177e190e07a26ab74f8b1efbfe2ef87da2116221318cb1c2e82baf7de06"++[[package]]+name = "basic-toml"+version = "0.1.10"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "ba62675e8242a4c4e806d12f11d136e626e6c8361d6b829310732241652a178a"+dependencies = [+ "serde",+]++[[package]]+name = "bitflags"+version = "2.10.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3"++[[package]]+name = "blake2"+version = "0.10.6"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "46502ad458c9a52b69d4d4d32775c788b7a1b85e8bc9d482d92250fc0e3f8efe"+dependencies = [+ "digest",+]++[[package]]+name = "blake2b_simd"+version = "1.0.4"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b79834656f71332577234b50bfc009996f7449e0c056884e6a02492ded0ca2f3"+dependencies = [+ "arrayref",+ "arrayvec",+ "constant_time_eq",+]++[[package]]+name = "block-buffer"+version = "0.10.4"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"+dependencies = [+ "generic-array",+]++[[package]]+name = "block-padding"+version = "0.3.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "a8894febbff9f758034a5b8e12d87918f56dfc64a8e1fe757d65e29041538d93"+dependencies = [+ "generic-array",+]++[[package]]+name = "bumpalo"+version = "3.19.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "5dd9dc738b7a8311c7ade152424974d8115f2cdad61e8dab8dac9f2362298510"++[[package]]+name = "bytes"+version = "1.11.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b35204fbdc0b3f4446b89fc1ac2cf84a8a68971995d0bf2e925ec7cd960f9cb3"++[[package]]+name = "camino"+version = "1.2.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "e629a66d692cb9ff1a1c664e41771b3dcaf961985a9774c0eb0bd1b51cf60a48"+dependencies = [+ "serde_core",+]++[[package]]+name = "cargo-platform"+version = "0.1.9"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "e35af189006b9c0f00a064685c727031e3ed2d8020f7ba284d78cc2671bd36ea"+dependencies = [+ "serde",+]++[[package]]+name = "cargo_metadata"+version = "0.19.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "dd5eb614ed4c27c5d706420e4320fbe3216ab31fa1c33cd8246ac36dae4479ba"+dependencies = [+ "camino",+ "cargo-platform",+ "semver",+ "serde",+ "serde_json",+ "thiserror",+]++[[package]]+name = "cc"+version = "1.2.53"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "755d2fce177175ffca841e9a06afdb2c4ab0f593d53b4dee48147dfaade85932"+dependencies = [+ "find-msvc-tools",+ "shlex",+]++[[package]]+name = "cfg-if"+version = "1.0.4"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"++[[package]]+name = "cfg_aliases"+version = "0.2.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"++[[package]]+name = "chacha20"+version = "0.9.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "c3613f74bd2eac03dad61bd53dbe620703d4371614fe0bc3b9f04dd36fe4e818"+dependencies = [+ "cfg-if",+ "cipher",+ "cpufeatures",+]++[[package]]+name = "cipher"+version = "0.4.4"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad"+dependencies = [+ "crypto-common",+ "inout",+ "zeroize",+]++[[package]]+name = "constant_time_eq"+version = "0.4.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "3d52eff69cd5e647efe296129160853a42795992097e8af39800e1060caeea9b"++[[package]]+name = "core-foundation"+version = "0.9.4"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f"+dependencies = [+ "core-foundation-sys",+ "libc",+]++[[package]]+name = "core-foundation"+version = "0.10.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b2a6cd9ae233e7f62ba4e9353e81a88df7fc8a5987b8d445b4d90c879bd156f6"+dependencies = [+ "core-foundation-sys",+ "libc",+]++[[package]]+name = "core-foundation-sys"+version = "0.8.7"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"++[[package]]+name = "cpufeatures"+version = "0.2.17"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280"+dependencies = [+ "libc",+]++[[package]]+name = "crypto-common"+version = "0.1.7"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a"+dependencies = [+ "generic-array",+ "rand_core 0.6.4",+ "typenum",+]++[[package]]+name = "crypto_secretstream"+version = "0.2.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9a6419214057ad50a13efccb3ad7714b86b848e3a5aa7b6cf5a3ff07edf387eb"+dependencies = [+ "aead",+ "chacha20",+ "getrandom 0.2.17",+ "poly1305",+ "rand_core 0.6.4",+ "subtle",+]++[[package]]+name = "curve25519-dalek"+version = "4.1.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "97fb8b7c4503de7d6ae7b42ab72a5a59857b4c937ec27a3d4539dba95b5ab2be"+dependencies = [+ "cfg-if",+ "cpufeatures",+ "curve25519-dalek-derive",+ "fiat-crypto",+ "rustc_version",+ "subtle",+ "zeroize",+]++[[package]]+name = "curve25519-dalek-derive"+version = "0.1.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3"+dependencies = [+ "proc-macro2",+ "quote",+ "syn",+]++[[package]]+name = "digest"+version = "0.10.7"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"+dependencies = [+ "block-buffer",+ "crypto-common",+ "subtle",+]++[[package]]+name = "displaydoc"+version = "0.2.5"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0"+dependencies = [+ "proc-macro2",+ "quote",+ "syn",+]++[[package]]+name = "encoding_rs"+version = "0.8.35"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3"+dependencies = [+ "cfg-if",+]++[[package]]+name = "ente-core"+version = "0.0.1"+dependencies = [+ "argon2",+ "base64",+ "blake2b_simd",+ "crypto_secretstream",+ "getrandom 0.2.17",+ "hex",+ "md-5",+ "rand_core 0.6.4",+ "reqwest",+ "salsa20",+ "serde",+ "serde_json",+ "subtle",+ "thiserror",+ "x25519-dalek",+ "xsalsa20poly1305",+ "zeroize",+]++[[package]]+name = "equivalent"+version = "1.0.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"++[[package]]+name = "errno"+version = "0.3.14"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"+dependencies = [+ "libc",+ "windows-sys 0.61.2",+]++[[package]]+name = "fallible-iterator"+version = "0.3.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649"++[[package]]+name = "fallible-streaming-iterator"+version = "0.1.9"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a"++[[package]]+name = "fastrand"+version = "2.3.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"++[[package]]+name = "fiat-crypto"+version = "0.2.9"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d"++[[package]]+name = "find-msvc-tools"+version = "0.1.8"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "8591b0bcc8a98a64310a2fae1bb3e9b8564dd10e381e6e28010fde8e8e8568db"++[[package]]+name = "fnv"+version = "1.0.7"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"++[[package]]+name = "foldhash"+version = "0.2.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb"++[[package]]+name = "form_urlencoded"+version = "1.2.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf"+dependencies = [+ "percent-encoding",+]++[[package]]+name = "fs-err"+version = "2.11.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "88a41f105fe1d5b6b34b2055e3dc59bb79b46b48b2040b9e6c7b4b5de097aa41"+dependencies = [+ "autocfg",+]++[[package]]+name = "futures-channel"+version = "0.3.31"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10"+dependencies = [+ "futures-core",+]++[[package]]+name = "futures-core"+version = "0.3.31"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e"++[[package]]+name = "futures-sink"+version = "0.3.31"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7"++[[package]]+name = "futures-task"+version = "0.3.31"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988"++[[package]]+name = "futures-util"+version = "0.3.31"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81"+dependencies = [+ "futures-core",+ "futures-task",+ "pin-project-lite",+ "pin-utils",+ "slab",+]++[[package]]+name = "generic-array"+version = "0.14.7"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"+dependencies = [+ "typenum",+ "version_check",+]++[[package]]+name = "getrandom"+version = "0.2.17"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0"+dependencies = [+ "cfg-if",+ "js-sys",+ "libc",+ "wasi",+ "wasm-bindgen",+]++[[package]]+name = "getrandom"+version = "0.3.4"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd"+dependencies = [+ "cfg-if",+ "js-sys",+ "libc",+ "r-efi",+ "wasip2",+ "wasm-bindgen",+]++[[package]]+name = "glob"+version = "0.3.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280"++[[package]]+name = "goblin"+version = "0.8.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "1b363a30c165f666402fe6a3024d3bec7ebc898f96a4a23bd1c99f8dbf3f4f47"+dependencies = [+ "log",+ "plain",+ "scroll",+]++[[package]]+name = "h2"+version = "0.4.13"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "2f44da3a8150a6703ed5d34e164b875fd14c2cdab9af1252a9a1020bde2bdc54"+dependencies = [+ "atomic-waker",+ "bytes",+ "fnv",+ "futures-core",+ "futures-sink",+ "http",+ "indexmap",+ "slab",+ "tokio",+ "tokio-util",+ "tracing",+]++[[package]]+name = "hashbrown"+version = "0.16.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100"+dependencies = [+ "foldhash",+]++[[package]]+name = "hashlink"+version = "0.11.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "ea0b22561a9c04a7cb1a302c013e0259cd3b4bb619f145b32f72b8b4bcbed230"+dependencies = [+ "hashbrown",+]++[[package]]+name = "heck"+version = "0.5.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"++[[package]]+name = "hex"+version = "0.4.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"++[[package]]+name = "http"+version = "1.4.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "e3ba2a386d7f85a81f119ad7498ebe444d2e22c2af0b86b069416ace48b3311a"+dependencies = [+ "bytes",+ "itoa",+]++[[package]]+name = "http-body"+version = "1.0.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184"+dependencies = [+ "bytes",+ "http",+]++[[package]]+name = "http-body-util"+version = "0.1.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b021d93e26becf5dc7e1b75b1bed1fd93124b374ceb73f43d4d4eafec896a64a"+dependencies = [+ "bytes",+ "futures-core",+ "http",+ "http-body",+ "pin-project-lite",+]++[[package]]+name = "httparse"+version = "1.10.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87"++[[package]]+name = "hyper"+version = "1.8.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "2ab2d4f250c3d7b1c9fcdff1cece94ea4e2dfbec68614f7b87cb205f24ca9d11"+dependencies = [+ "atomic-waker",+ "bytes",+ "futures-channel",+ "futures-core",+ "h2",+ "http",+ "http-body",+ "httparse",+ "itoa",+ "pin-project-lite",+ "pin-utils",+ "smallvec",+ "tokio",+ "want",+]++[[package]]+name = "hyper-rustls"+version = "0.27.7"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "e3c93eb611681b207e1fe55d5a71ecf91572ec8a6705cdb6857f7d8d5242cf58"+dependencies = [+ "http",+ "hyper",+ "hyper-util",+ "rustls",+ "rustls-native-certs",+ "rustls-pki-types",+ "tokio",+ "tokio-rustls",+ "tower-service",+]++[[package]]+name = "hyper-util"+version = "0.1.19"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "727805d60e7938b76b826a6ef209eb70eaa1812794f9424d4a4e2d740662df5f"+dependencies = [+ "base64",+ "bytes",+ "futures-channel",+ "futures-core",+ "futures-util",+ "http",+ "http-body",+ "hyper",+ "ipnet",+ "libc",+ "percent-encoding",+ "pin-project-lite",+ "socket2",+ "system-configuration",+ "tokio",+ "tower-service",+ "tracing",+ "windows-registry",+]++[[package]]+name = "icu_collections"+version = "2.1.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "4c6b649701667bbe825c3b7e6388cb521c23d88644678e83c0c4d0a621a34b43"+dependencies = [+ "displaydoc",+ "potential_utf",+ "yoke",+ "zerofrom",+ "zerovec",+]++[[package]]+name = "icu_locale_core"+version = "2.1.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "edba7861004dd3714265b4db54a3c390e880ab658fec5f7db895fae2046b5bb6"+dependencies = [+ "displaydoc",+ "litemap",+ "tinystr",+ "writeable",+ "zerovec",+]++[[package]]+name = "icu_normalizer"+version = "2.1.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "5f6c8828b67bf8908d82127b2054ea1b4427ff0230ee9141c54251934ab1b599"+dependencies = [+ "icu_collections",+ "icu_normalizer_data",+ "icu_properties",+ "icu_provider",+ "smallvec",+ "zerovec",+]++[[package]]+name = "icu_normalizer_data"+version = "2.1.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "7aedcccd01fc5fe81e6b489c15b247b8b0690feb23304303a9e560f37efc560a"++[[package]]+name = "icu_properties"+version = "2.1.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "020bfc02fe870ec3a66d93e677ccca0562506e5872c650f893269e08615d74ec"+dependencies = [+ "icu_collections",+ "icu_locale_core",+ "icu_properties_data",+ "icu_provider",+ "zerotrie",+ "zerovec",+]++[[package]]+name = "icu_properties_data"+version = "2.1.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "616c294cf8d725c6afcd8f55abc17c56464ef6211f9ed59cccffe534129c77af"++[[package]]+name = "icu_provider"+version = "2.1.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "85962cf0ce02e1e0a629cc34e7ca3e373ce20dda4c4d7294bbd0bf1fdb59e614"+dependencies = [+ "displaydoc",+ "icu_locale_core",+ "writeable",+ "yoke",+ "zerofrom",+ "zerotrie",+ "zerovec",+]++[[package]]+name = "idna"+version = "1.1.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de"+dependencies = [+ "idna_adapter",+ "smallvec",+ "utf8_iter",+]++[[package]]+name = "idna_adapter"+version = "1.2.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "3acae9609540aa318d1bc588455225fb2085b9ed0c4f6bd0d9d5bcd86f1a0344"+dependencies = [+ "icu_normalizer",+ "icu_properties",+]++[[package]]+name = "indexmap"+version = "2.13.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017"+dependencies = [+ "equivalent",+ "hashbrown",+ "serde",+ "serde_core",+]++[[package]]+name = "inout"+version = "0.1.4"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01"+dependencies = [+ "block-padding",+ "generic-array",+]++[[package]]+name = "ipnet"+version = "2.11.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130"++[[package]]+name = "iri-string"+version = "0.7.10"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "c91338f0783edbd6195decb37bae672fd3b165faffb89bf7b9e6942f8b1a731a"+dependencies = [+ "memchr",+ "serde",+]++[[package]]+name = "itoa"+version = "1.0.17"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2"++[[package]]+name = "js-sys"+version = "0.3.85"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "8c942ebf8e95485ca0d52d97da7c5a2c387d0e7f0ba4c35e93bfcaee045955b3"+dependencies = [+ "once_cell",+ "wasm-bindgen",+]++[[package]]+name = "libc"+version = "0.2.180"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc"++[[package]]+name = "libsqlite3-sys"+version = "0.36.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "95b4103cffefa72eb8428cb6b47d6627161e51c2739fc5e3b734584157bc642a"+dependencies = [+ "cc",+ "pkg-config",+ "vcpkg",+]++[[package]]+name = "linux-raw-sys"+version = "0.11.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039"++[[package]]+name = "litemap"+version = "0.8.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "6373607a59f0be73a39b6fe456b8192fcc3585f602af20751600e974dd455e77"++[[package]]+name = "llmchat-db"+version = "0.1.0"+dependencies = [+ "ente-core",+ "rusqlite",+ "serde",+ "serde_json",+ "thiserror",+ "uuid",+ "zeroize",+]++[[package]]+name = "llmchat_db_uniffi"+version = "0.1.0"+dependencies = [+ "llmchat-db",+ "serde",+ "thiserror",+ "uniffi",+ "uuid",+]++[[package]]+name = "log"+version = "0.4.29"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897"++[[package]]+name = "lru-slab"+version = "0.1.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154"++[[package]]+name = "md-5"+version = "0.10.6"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf"+dependencies = [+ "cfg-if",+ "digest",+]++[[package]]+name = "memchr"+version = "2.7.6"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273"++[[package]]+name = "mime"+version = "0.3.17"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"++[[package]]+name = "minimal-lexical"+version = "0.2.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"++[[package]]+name = "mio"+version = "1.1.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "a69bcab0ad47271a0234d9422b131806bf3968021e5dc9328caf2d4cd58557fc"+dependencies = [+ "libc",+ "wasi",+ "windows-sys 0.61.2",+]++[[package]]+name = "nom"+version = "7.1.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"+dependencies = [+ "memchr",+ "minimal-lexical",+]++[[package]]+name = "once_cell"+version = "1.21.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"++[[package]]+name = "opaque-debug"+version = "0.3.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381"++[[package]]+name = "openssl-probe"+version = "0.2.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9f50d9b3dabb09ecd771ad0aa242ca6894994c130308ca3d7684634df8037391"++[[package]]+name = "password-hash"+version = "0.5.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "346f04948ba92c43e8469c1ee6736c7563d71012b17d40745260fe106aac2166"+dependencies = [+ "base64ct",+ "rand_core 0.6.4",+ "subtle",+]++[[package]]+name = "percent-encoding"+version = "2.3.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220"++[[package]]+name = "pin-project-lite"+version = "0.2.16"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b"++[[package]]+name = "pin-utils"+version = "0.1.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"++[[package]]+name = "pkg-config"+version = "0.3.32"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c"++[[package]]+name = "plain"+version = "0.2.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6"++[[package]]+name = "poly1305"+version = "0.8.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "8159bd90725d2df49889a078b54f4f79e87f1f8a8444194cdca81d38f5393abf"+dependencies = [+ "cpufeatures",+ "opaque-debug",+ "universal-hash",+]++[[package]]+name = "potential_utf"+version = "0.1.4"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b73949432f5e2a09657003c25bca5e19a0e9c84f8058ca374f49e0ebe605af77"+dependencies = [+ "zerovec",+]++[[package]]+name = "ppv-lite86"+version = "0.2.21"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9"+dependencies = [+ "zerocopy",+]++[[package]]+name = "proc-macro2"+version = "1.0.105"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "535d180e0ecab6268a3e718bb9fd44db66bbbc256257165fc699dadf70d16fe7"+dependencies = [+ "unicode-ident",+]++[[package]]+name = "quinn"+version = "0.11.9"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b9e20a958963c291dc322d98411f541009df2ced7b5a4f2bd52337638cfccf20"+dependencies = [+ "bytes",+ "cfg_aliases",+ "pin-project-lite",+ "quinn-proto",+ "quinn-udp",+ "rustc-hash",+ "rustls",+ "socket2",+ "thiserror",+ "tokio",+ "tracing",+ "web-time",+]++[[package]]+name = "quinn-proto"+version = "0.11.13"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "f1906b49b0c3bc04b5fe5d86a77925ae6524a19b816ae38ce1e426255f1d8a31"+dependencies = [+ "bytes",+ "getrandom 0.3.4",+ "lru-slab",+ "rand",+ "ring",+ "rustc-hash",+ "rustls",+ "rustls-pki-types",+ "slab",+ "thiserror",+ "tinyvec",+ "tracing",+ "web-time",+]++[[package]]+name = "quinn-udp"+version = "0.5.14"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "addec6a0dcad8a8d96a771f815f0eaf55f9d1805756410b39f5fa81332574cbd"+dependencies = [+ "cfg_aliases",+ "libc",+ "once_cell",+ "socket2",+ "tracing",+ "windows-sys 0.60.2",+]++[[package]]+name = "quote"+version = "1.0.43"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "dc74d9a594b72ae6656596548f56f667211f8a97b3d4c3d467150794690dc40a"+dependencies = [+ "proc-macro2",+]++[[package]]+name = "r-efi"+version = "5.3.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"++[[package]]+name = "rand"+version = "0.9.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1"+dependencies = [+ "rand_chacha",+ "rand_core 0.9.5",+]++[[package]]+name = "rand_chacha"+version = "0.9.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb"+dependencies = [+ "ppv-lite86",+ "rand_core 0.9.5",+]++[[package]]+name = "rand_core"+version = "0.6.4"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"+dependencies = [+ "getrandom 0.2.17",+]++[[package]]+name = "rand_core"+version = "0.9.5"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c"+dependencies = [+ "getrandom 0.3.4",+]++[[package]]+name = "reqwest"+version = "0.12.28"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "eddd3ca559203180a307f12d114c268abf583f59b03cb906fd0b3ff8646c1147"+dependencies = [+ "base64",+ "bytes",+ "encoding_rs",+ "futures-core",+ "h2",+ "http",+ "http-body",+ "http-body-util",+ "hyper",+ "hyper-rustls",+ "hyper-util",+ "js-sys",+ "log",+ "mime",+ "percent-encoding",+ "pin-project-lite",+ "quinn",+ "rustls",+ "rustls-native-certs",+ "rustls-pki-types",+ "serde",+ "serde_json",+ "serde_urlencoded",+ "sync_wrapper",+ "tokio",+ "tokio-rustls",+ "tower",+ "tower-http",+ "tower-service",+ "url",+ "wasm-bindgen",+ "wasm-bindgen-futures",+ "web-sys",+]++[[package]]+name = "ring"+version = "0.17.14"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7"+dependencies = [+ "cc",+ "cfg-if",+ "getrandom 0.2.17",+ "libc",+ "untrusted",+ "windows-sys 0.52.0",+]++[[package]]+name = "rsqlite-vfs"+version = "0.1.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "a8a1f2315036ef6b1fbacd1972e8ee7688030b0a2121edfc2a6550febd41574d"+dependencies = [+ "hashbrown",+ "thiserror",+]++[[package]]+name = "rusqlite"+version = "0.38.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "f1c93dd1c9683b438c392c492109cb702b8090b2bfc8fed6f6e4eb4523f17af3"+dependencies = [+ "bitflags",+ "fallible-iterator",+ "fallible-streaming-iterator",+ "hashlink",+ "libsqlite3-sys",+ "smallvec",+ "sqlite-wasm-rs",+]++[[package]]+name = "rustc-hash"+version = "2.1.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d"++[[package]]+name = "rustc_version"+version = "0.4.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92"+dependencies = [+ "semver",+]++[[package]]+name = "rustix"+version = "1.1.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "146c9e247ccc180c1f61615433868c99f3de3ae256a30a43b49f67c2d9171f34"+dependencies = [+ "bitflags",+ "errno",+ "libc",+ "linux-raw-sys",+ "windows-sys 0.61.2",+]++[[package]]+name = "rustls"+version = "0.23.36"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "c665f33d38cea657d9614f766881e4d510e0eda4239891eea56b4cadcf01801b"+dependencies = [+ "once_cell",+ "ring",+ "rustls-pki-types",+ "rustls-webpki",+ "subtle",+ "zeroize",+]++[[package]]+name = "rustls-native-certs"+version = "0.8.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "612460d5f7bea540c490b2b6395d8e34a953e52b491accd6c86c8164c5932a63"+dependencies = [+ "openssl-probe",+ "rustls-pki-types",+ "schannel",+ "security-framework",+]++[[package]]+name = "rustls-pki-types"+version = "1.14.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "be040f8b0a225e40375822a563fa9524378b9d63112f53e19ffff34df5d33fdd"+dependencies = [+ "web-time",+ "zeroize",+]++[[package]]+name = "rustls-webpki"+version = "0.103.9"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "d7df23109aa6c1567d1c575b9952556388da57401e4ace1d15f79eedad0d8f53"+dependencies = [+ "ring",+ "rustls-pki-types",+ "untrusted",+]++[[package]]+name = "rustversion"+version = "1.0.22"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"++[[package]]+name = "ryu"+version = "1.0.22"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "a50f4cf475b65d88e057964e0e9bb1f0aa9bbb2036dc65c64596b42932536984"++[[package]]+name = "salsa20"+version = "0.10.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "97a22f5af31f73a954c10289c93e8a50cc23d971e80ee446f1f6f7137a088213"+dependencies = [+ "cipher",+]++[[package]]+name = "schannel"+version = "0.1.28"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "891d81b926048e76efe18581bf793546b4c0eaf8448d72be8de2bbee5fd166e1"+dependencies = [+ "windows-sys 0.61.2",+]++[[package]]+name = "scroll"+version = "0.12.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "6ab8598aa408498679922eff7fa985c25d58a90771bd6be794434c5277eab1a6"+dependencies = [+ "scroll_derive",+]++[[package]]+name = "scroll_derive"+version = "0.12.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "1783eabc414609e28a5ba76aee5ddd52199f7107a0b24c2e9746a1ecc34a683d"+dependencies = [+ "proc-macro2",+ "quote",+ "syn",+]++[[package]]+name = "security-framework"+version = "3.5.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b3297343eaf830f66ede390ea39da1d462b6b0c1b000f420d0a83f898bbbe6ef"+dependencies = [+ "bitflags",+ "core-foundation 0.10.1",+ "core-foundation-sys",+ "libc",+ "security-framework-sys",+]++[[package]]+name = "security-framework-sys"+version = "2.15.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "cc1f0cbffaac4852523ce30d8bd3c5cdc873501d96ff467ca09b6767bb8cd5c0"+dependencies = [+ "core-foundation-sys",+ "libc",+]++[[package]]+name = "semver"+version = "1.0.27"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2"+dependencies = [+ "serde",+ "serde_core",+]++[[package]]+name = "serde"+version = "1.0.228"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"+dependencies = [+ "serde_core",+ "serde_derive",+]++[[package]]+name = "serde_core"+version = "1.0.228"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"+dependencies = [+ "serde_derive",+]++[[package]]+name = "serde_derive"+version = "1.0.228"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"+dependencies = [+ "proc-macro2",+ "quote",+ "syn",+]++[[package]]+name = "serde_json"+version = "1.0.149"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86"+dependencies = [+ "itoa",+ "memchr",+ "serde",+ "serde_core",+ "zmij",+]++[[package]]+name = "serde_spanned"+version = "1.0.4"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "f8bbf91e5a4d6315eee45e704372590b30e260ee83af6639d64557f51b067776"+dependencies = [+ "serde_core",+]++[[package]]+name = "serde_urlencoded"+version = "0.7.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd"+dependencies = [+ "form_urlencoded",+ "itoa",+ "ryu",+ "serde",+]++[[package]]+name = "shlex"+version = "1.3.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"++[[package]]+name = "siphasher"+version = "1.0.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d"++[[package]]+name = "slab"+version = "0.4.11"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "7a2ae44ef20feb57a68b23d846850f861394c2e02dc425a50098ae8c90267589"++[[package]]+name = "smallvec"+version = "1.15.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03"++[[package]]+name = "smawk"+version = "0.3.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b7c388c1b5e93756d0c740965c41e8822f866621d41acbdf6336a6a168f8840c"++[[package]]+name = "socket2"+version = "0.6.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "17129e116933cf371d018bb80ae557e889637989d8638274fb25622827b03881"+dependencies = [+ "libc",+ "windows-sys 0.60.2",+]++[[package]]+name = "sqlite-wasm-rs"+version = "0.5.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "2f4206ed3a67690b9c29b77d728f6acc3ce78f16bf846d83c94f76400320181b"+dependencies = [+ "cc",+ "js-sys",+ "rsqlite-vfs",+ "wasm-bindgen",+]++[[package]]+name = "stable_deref_trait"+version = "1.2.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596"++[[package]]+name = "static_assertions"+version = "1.1.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"++[[package]]+name = "subtle"+version = "2.6.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"++[[package]]+name = "syn"+version = "2.0.114"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "d4d107df263a3013ef9b1879b0df87d706ff80f65a86ea879bd9c31f9b307c2a"+dependencies = [+ "proc-macro2",+ "quote",+ "unicode-ident",+]++[[package]]+name = "sync_wrapper"+version = "1.0.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263"+dependencies = [+ "futures-core",+]++[[package]]+name = "synstructure"+version = "0.13.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2"+dependencies = [+ "proc-macro2",+ "quote",+ "syn",+]++[[package]]+name = "system-configuration"+version = "0.6.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b"+dependencies = [+ "bitflags",+ "core-foundation 0.9.4",+ "system-configuration-sys",+]++[[package]]+name = "system-configuration-sys"+version = "0.6.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4"+dependencies = [+ "core-foundation-sys",+ "libc",+]++[[package]]+name = "tempfile"+version = "3.24.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "655da9c7eb6305c55742045d5a8d2037996d61d8de95806335c7c86ce0f82e9c"+dependencies = [+ "fastrand",+ "getrandom 0.3.4",+ "once_cell",+ "rustix",+ "windows-sys 0.61.2",+]++[[package]]+name = "textwrap"+version = "0.16.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "c13547615a44dc9c452a8a534638acdf07120d4b6847c8178705da06306a3057"+dependencies = [+ "smawk",+]++[[package]]+name = "thiserror"+version = "2.0.18"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4"+dependencies = [+ "thiserror-impl",+]++[[package]]+name = "thiserror-impl"+version = "2.0.18"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5"+dependencies = [+ "proc-macro2",+ "quote",+ "syn",+]++[[package]]+name = "tinystr"+version = "0.8.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "42d3e9c45c09de15d06dd8acf5f4e0e399e85927b7f00711024eb7ae10fa4869"+dependencies = [+ "displaydoc",+ "zerovec",+]++[[package]]+name = "tinyvec"+version = "1.10.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "bfa5fdc3bce6191a1dbc8c02d5c8bffcf557bafa17c124c5264a458f1b0613fa"+dependencies = [+ "tinyvec_macros",+]++[[package]]+name = "tinyvec_macros"+version = "0.1.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"++[[package]]+name = "tokio"+version = "1.49.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "72a2903cd7736441aac9df9d7688bd0ce48edccaadf181c3b90be801e81d3d86"+dependencies = [+ "bytes",+ "libc",+ "mio",+ "pin-project-lite",+ "socket2",+ "windows-sys 0.61.2",+]++[[package]]+name = "tokio-rustls"+version = "0.26.4"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "1729aa945f29d91ba541258c8df89027d5792d85a8841fb65e8bf0f4ede4ef61"+dependencies = [+ "rustls",+ "tokio",+]++[[package]]+name = "tokio-util"+version = "0.7.18"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9ae9cec805b01e8fc3fd2fe289f89149a9b66dd16786abd8b19cfa7b48cb0098"+dependencies = [+ "bytes",+ "futures-core",+ "futures-sink",+ "pin-project-lite",+ "tokio",+]++[[package]]+name = "toml"+version = "0.9.11+spec-1.1.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "f3afc9a848309fe1aaffaed6e1546a7a14de1f935dc9d89d32afd9a44bab7c46"+dependencies = [+ "indexmap",+ "serde_core",+ "serde_spanned",+ "toml_datetime",+ "toml_parser",+ "toml_writer",+ "winnow",+]++[[package]]+name = "toml_datetime"+version = "0.7.5+spec-1.1.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "92e1cfed4a3038bc5a127e35a2d360f145e1f4b971b551a2ba5fd7aedf7e1347"+dependencies = [+ "serde_core",+]++[[package]]+name = "toml_parser"+version = "1.0.6+spec-1.1.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "a3198b4b0a8e11f09dd03e133c0280504d0801269e9afa46362ffde1cbeebf44"+dependencies = [+ "winnow",+]++[[package]]+name = "toml_writer"+version = "1.0.6+spec-1.1.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "ab16f14aed21ee8bfd8ec22513f7287cd4a91aa92e44edfe2c17ddd004e92607"++[[package]]+name = "tower"+version = "0.5.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4"+dependencies = [+ "futures-core",+ "futures-util",+ "pin-project-lite",+ "sync_wrapper",+ "tokio",+ "tower-layer",+ "tower-service",+]++[[package]]+name = "tower-http"+version = "0.6.8"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "d4e6559d53cc268e5031cd8429d05415bc4cb4aefc4aa5d6cc35fbf5b924a1f8"+dependencies = [+ "bitflags",+ "bytes",+ "futures-util",+ "http",+ "http-body",+ "iri-string",+ "pin-project-lite",+ "tower",+ "tower-layer",+ "tower-service",+]++[[package]]+name = "tower-layer"+version = "0.3.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e"++[[package]]+name = "tower-service"+version = "0.3.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3"++[[package]]+name = "tracing"+version = "0.1.44"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100"+dependencies = [+ "pin-project-lite",+ "tracing-core",+]++[[package]]+name = "tracing-core"+version = "0.1.36"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a"+dependencies = [+ "once_cell",+]++[[package]]+name = "try-lock"+version = "0.2.5"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"++[[package]]+name = "typenum"+version = "1.19.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb"++[[package]]+name = "unicode-ident"+version = "1.0.22"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5"++[[package]]+name = "uniffi"+version = "0.31.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b8c6dec3fc6645f71a16a3fa9ff57991028153bd194ca97f4b55e610c73ce66a"+dependencies = [+ "anyhow",+ "cargo_metadata",+ "uniffi_bindgen",+ "uniffi_core",+ "uniffi_macros",+ "uniffi_pipeline",+]++[[package]]+name = "uniffi_bindgen"+version = "0.31.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "4ed0150801958d4825da56a41c71f000a457ac3a4613fa9647df78ac4b6b6881"+dependencies = [+ "anyhow",+ "askama",+ "camino",+ "cargo_metadata",+ "fs-err",+ "glob",+ "goblin",+ "heck",+ "indexmap",+ "once_cell",+ "serde",+ "tempfile",+ "textwrap",+ "toml",+ "uniffi_internal_macros",+ "uniffi_meta",+ "uniffi_pipeline",+ "uniffi_udl",+]++[[package]]+name = "uniffi_core"+version = "0.31.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b0ef62e69762fbb9386dcb6c87cd3dd05d525fa8a3a579a290892e60ddbda47e"+dependencies = [+ "anyhow",+ "bytes",+ "once_cell",+ "static_assertions",+]++[[package]]+name = "uniffi_internal_macros"+version = "0.31.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "98f51ebca0d9a4b2aa6c644d5ede45c56f73906b96403c08a1985e75ccb64a01"+dependencies = [+ "anyhow",+ "indexmap",+ "proc-macro2",+ "quote",+ "syn",+]++[[package]]+name = "uniffi_macros"+version = "0.31.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "db9d12529f1223d014fd501e5f29ca0884d15d6ed5ddddd9f506e55350327dc3"+dependencies = [+ "camino",+ "fs-err",+ "once_cell",+ "proc-macro2",+ "quote",+ "serde",+ "syn",+ "toml",+ "uniffi_meta",+]++[[package]]+name = "uniffi_meta"+version = "0.31.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9df6d413db2827c68588f8149d30d49b71d540d46539e435b23a7f7dbd4d4f86"+dependencies = [+ "anyhow",+ "siphasher",+ "uniffi_internal_macros",+ "uniffi_pipeline",+]++[[package]]+name = "uniffi_pipeline"+version = "0.31.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "a806dddc8208f22efd7e95a5cdf88ed43d0f3271e8f63b47e757a8bbdb43b63a"+dependencies = [+ "anyhow",+ "heck",+ "indexmap",+ "tempfile",+ "uniffi_internal_macros",+]++[[package]]+name = "uniffi_udl"+version = "0.31.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "0d1a7339539bf6f6fa3e9b534dece13f778bda2d54b1a6d4e40b4d6090ac26e7"+dependencies = [+ "anyhow",+ "textwrap",+ "uniffi_meta",+ "weedle2",+]++[[package]]+name = "universal-hash"+version = "0.5.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "fc1de2c688dc15305988b563c3854064043356019f97a4b46276fe734c4f07ea"+dependencies = [+ "crypto-common",+ "subtle",+]++[[package]]+name = "untrusted"+version = "0.9.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1"++[[package]]+name = "url"+version = "2.5.8"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed"+dependencies = [+ "form_urlencoded",+ "idna",+ "percent-encoding",+ "serde",+]++[[package]]+name = "utf8_iter"+version = "1.0.4"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"++[[package]]+name = "uuid"+version = "1.19.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "e2e054861b4bd027cd373e18e8d8d8e6548085000e41290d95ce0c373a654b4a"+dependencies = [+ "getrandom 0.3.4",+ "js-sys",+ "uuid-rng-internal",+ "wasm-bindgen",+]++[[package]]+name = "uuid-rng-internal"+version = "1.19.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "8d0021aebf9af0cbec73af2f884a2cd0a41d984c00e42f27baa11856ab480e2c"+dependencies = [+ "getrandom 0.3.4",+]++[[package]]+name = "vcpkg"+version = "0.2.15"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"++[[package]]+name = "version_check"+version = "0.9.5"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"++[[package]]+name = "want"+version = "0.3.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e"+dependencies = [+ "try-lock",+]++[[package]]+name = "wasi"+version = "0.11.1+wasi-snapshot-preview1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"++[[package]]+name = "wasip2"+version = "1.0.2+wasi-0.2.9"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9517f9239f02c069db75e65f174b3da828fe5f5b945c4dd26bd25d89c03ebcf5"+dependencies = [+ "wit-bindgen",+]++[[package]]+name = "wasm-bindgen"+version = "0.2.108"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "64024a30ec1e37399cf85a7ffefebdb72205ca1c972291c51512360d90bd8566"+dependencies = [+ "cfg-if",+ "once_cell",+ "rustversion",+ "wasm-bindgen-macro",+ "wasm-bindgen-shared",+]++[[package]]+name = "wasm-bindgen-futures"+version = "0.4.58"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "70a6e77fd0ae8029c9ea0063f87c46fde723e7d887703d74ad2616d792e51e6f"+dependencies = [+ "cfg-if",+ "futures-util",+ "js-sys",+ "once_cell",+ "wasm-bindgen",+ "web-sys",+]++[[package]]+name = "wasm-bindgen-macro"+version = "0.2.108"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "008b239d9c740232e71bd39e8ef6429d27097518b6b30bdf9086833bd5b6d608"+dependencies = [+ "quote",+ "wasm-bindgen-macro-support",+]++[[package]]+name = "wasm-bindgen-macro-support"+version = "0.2.108"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "5256bae2d58f54820e6490f9839c49780dff84c65aeab9e772f15d5f0e913a55"+dependencies = [+ "bumpalo",+ "proc-macro2",+ "quote",+ "syn",+ "wasm-bindgen-shared",+]++[[package]]+name = "wasm-bindgen-shared"+version = "0.2.108"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "1f01b580c9ac74c8d8f0c0e4afb04eeef2acf145458e52c03845ee9cd23e3d12"+dependencies = [+ "unicode-ident",+]++[[package]]+name = "web-sys"+version = "0.3.85"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "312e32e551d92129218ea9a2452120f4aabc03529ef03e4d0d82fb2780608598"+dependencies = [+ "js-sys",+ "wasm-bindgen",+]++[[package]]+name = "web-time"+version = "1.1.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb"+dependencies = [+ "js-sys",+ "wasm-bindgen",+]++[[package]]+name = "weedle2"+version = "5.0.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "998d2c24ec099a87daf9467808859f9d82b61f1d9c9701251aea037f514eae0e"+dependencies = [+ "nom",+]++[[package]]+name = "windows-link"+version = "0.2.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"++[[package]]+name = "windows-registry"+version = "0.6.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "02752bf7fbdcce7f2a27a742f798510f3e5ad88dbe84871e5168e2120c3d5720"+dependencies = [+ "windows-link",+ "windows-result",+ "windows-strings",+]++[[package]]+name = "windows-result"+version = "0.4.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5"+dependencies = [+ "windows-link",+]++[[package]]+name = "windows-strings"+version = "0.5.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091"+dependencies = [+ "windows-link",+]++[[package]]+name = "windows-sys"+version = "0.52.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"+dependencies = [+ "windows-targets 0.52.6",+]++[[package]]+name = "windows-sys"+version = "0.60.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb"+dependencies = [+ "windows-targets 0.53.5",+]++[[package]]+name = "windows-sys"+version = "0.61.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"+dependencies = [+ "windows-link",+]++[[package]]+name = "windows-targets"+version = "0.52.6"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"+dependencies = [+ "windows_aarch64_gnullvm 0.52.6",+ "windows_aarch64_msvc 0.52.6",+ "windows_i686_gnu 0.52.6",+ "windows_i686_gnullvm 0.52.6",+ "windows_i686_msvc 0.52.6",+ "windows_x86_64_gnu 0.52.6",+ "windows_x86_64_gnullvm 0.52.6",+ "windows_x86_64_msvc 0.52.6",+]++[[package]]+name = "windows-targets"+version = "0.53.5"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3"+dependencies = [+ "windows-link",+ "windows_aarch64_gnullvm 0.53.1",+ "windows_aarch64_msvc 0.53.1",+ "windows_i686_gnu 0.53.1",+ "windows_i686_gnullvm 0.53.1",+ "windows_i686_msvc 0.53.1",+ "windows_x86_64_gnu 0.53.1",+ "windows_x86_64_gnullvm 0.53.1",+ "windows_x86_64_msvc 0.53.1",+]++[[package]]+name = "windows_aarch64_gnullvm"+version = "0.52.6"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"++[[package]]+name = "windows_aarch64_gnullvm"+version = "0.53.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53"++[[package]]+name = "windows_aarch64_msvc"+version = "0.52.6"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"++[[package]]+name = "windows_aarch64_msvc"+version = "0.53.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006"++[[package]]+name = "windows_i686_gnu"+version = "0.52.6"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"++[[package]]+name = "windows_i686_gnu"+version = "0.53.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3"++[[package]]+name = "windows_i686_gnullvm"+version = "0.52.6"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"++[[package]]+name = "windows_i686_gnullvm"+version = "0.53.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c"++[[package]]+name = "windows_i686_msvc"+version = "0.52.6"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"++[[package]]+name = "windows_i686_msvc"+version = "0.53.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2"++[[package]]+name = "windows_x86_64_gnu"+version = "0.52.6"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"++[[package]]+name = "windows_x86_64_gnu"+version = "0.53.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499"++[[package]]+name = "windows_x86_64_gnullvm"+version = "0.52.6"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"++[[package]]+name = "windows_x86_64_gnullvm"+version = "0.53.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1"++[[package]]+name = "windows_x86_64_msvc"+version = "0.52.6"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"++[[package]]+name = "windows_x86_64_msvc"+version = "0.53.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650"++[[package]]+name = "winnow"+version = "0.7.14"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "5a5364e9d77fcdeeaa6062ced926ee3381faa2ee02d3eb83a5c27a8825540829"+dependencies = [+ "memchr",+]++[[package]]+name = "wit-bindgen"+version = "0.51.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5"++[[package]]+name = "writeable"+version = "0.6.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9edde0db4769d2dc68579893f2306b26c6ecfbe0ef499b013d731b7b9247e0b9"++[[package]]+name = "x25519-dalek"+version = "2.0.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "c7e468321c81fb07fa7f4c636c3972b9100f0346e5b6a9f2bd0603a52f7ed277"+dependencies = [+ "curve25519-dalek",+ "rand_core 0.6.4",+ "serde",+ "zeroize",+]++[[package]]+name = "xsalsa20poly1305"+version = "0.9.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "02a6dad357567f81cd78ee75f7c61f1b30bb2fe4390be8fb7c69e2ac8dffb6c7"+dependencies = [+ "aead",+ "poly1305",+ "salsa20",+ "subtle",+ "zeroize",+]++[[package]]+name = "yoke"+version = "0.8.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "72d6e5c6afb84d73944e5cedb052c4680d5657337201555f9f2a16b7406d4954"+dependencies = [+ "stable_deref_trait",+ "yoke-derive",+ "zerofrom",+]++[[package]]+name = "yoke-derive"+version = "0.8.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b659052874eb698efe5b9e8cf382204678a0086ebf46982b79d6ca3182927e5d"+dependencies = [+ "proc-macro2",+ "quote",+ "syn",+ "synstructure",+]++[[package]]+name = "zerocopy"+version = "0.8.33"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "668f5168d10b9ee831de31933dc111a459c97ec93225beb307aed970d1372dfd"+dependencies = [+ "zerocopy-derive",+]++[[package]]+name = "zerocopy-derive"+version = "0.8.33"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "2c7962b26b0a8685668b671ee4b54d007a67d4eaf05fda79ac0ecf41e32270f1"+dependencies = [+ "proc-macro2",+ "quote",+ "syn",+]++[[package]]+name = "zerofrom"+version = "0.1.6"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "50cc42e0333e05660c3587f3bf9d0478688e15d870fab3346451ce7f8c9fbea5"+dependencies = [+ "zerofrom-derive",+]++[[package]]+name = "zerofrom-derive"+version = "0.1.6"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502"+dependencies = [+ "proc-macro2",+ "quote",+ "syn",+ "synstructure",+]++[[package]]+name = "zeroize"+version = "1.8.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0"+dependencies = [+ "zeroize_derive",+]++[[package]]+name = "zeroize_derive"+version = "1.4.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "85a5b4158499876c763cb03bc4e49185d3cccbabb15b33c627f7884f43db852e"+dependencies = [+ "proc-macro2",+ "quote",+ "syn",+]++[[package]]+name = "zerotrie"+version = "0.2.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "2a59c17a5562d507e4b54960e8569ebee33bee890c70aa3fe7b97e85a9fd7851"+dependencies = [+ "displaydoc",+ "yoke",+ "zerofrom",+]++[[package]]+name = "zerovec"+version = "0.11.5"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "6c28719294829477f525be0186d13efa9a3c602f7ec202ca9e353d310fb9a002"+dependencies = [+ "yoke",+ "zerofrom",+ "zerovec-derive",+]++[[package]]+name = "zerovec-derive"+version = "0.11.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "eadce39539ca5cb3985590102671f2567e659fca9666581ad3411d59207951f3"+dependencies = [+ "proc-macro2",+ "quote",+ "syn",+]++[[package]]+name = "zmij"+version = "1.0.16"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "dfcd145825aace48cff44a8844de64bf75feec3080e0aa5cdbde72961ae51a65"diff --git a/rust/llmchat_db_uniffi/Cargo.toml b/rust/llmchat_db_uniffi/Cargo.tomlnew file mode 100644index 0000000000..440ef828ca--- /dev/null+++ b/rust/llmchat_db_uniffi/Cargo.toml@@ -0,0 +1,16 @@+[package]+name = "llmchat_db_uniffi"+version = "0.1.0"+edition = "2024"++[lib]+name = "llmchat_db_uniffi"+crate-type = ["staticlib", "cdylib"]++[dependencies]+llmchat-db = { path = "../llmchat-db" }+serde = { version = "1", features = ["derive"] }+thiserror = "2"+uniffi = { version = "0.31.0" }+uuid = { version = "1" }+diff --git a/rust/llmchat_db_uniffi/build.rs b/rust/llmchat_db_uniffi/build.rsnew file mode 100644index 0000000000..f328e4d9d0--- /dev/null+++ b/rust/llmchat_db_uniffi/build.rs@@ -0,0 +1 @@+fn main() {}diff --git a/rust/llmchat_db_uniffi/src/api.rs b/rust/llmchat_db_uniffi/src/api.rsnew file mode 100644index 0000000000..8de67c51dc--- /dev/null+++ b/rust/llmchat_db_uniffi/src/api.rs@@ -0,0 +1,201 @@+use llmchat_db as core;+use thiserror::Error;+use uuid::Uuid;++#[derive(Debug, Error, uniffi::Error)]+pub enum DbError {+ #[error("{0}")]+ Message(String),+}++impl From<core::Error> for DbError {+ fn from(err: core::Error) -> Self {+ DbError::Message(err.to_string())+ }+}++#[derive(Debug, Clone, uniffi::Record)]+pub struct Session {+ pub uuid: String,+ pub title: String,+ pub created_at_us: i64,+ pub updated_at_us: i64,+ pub remote_id: Option<String>,+ pub needs_sync: bool,+ pub deleted_at_us: Option<i64>,+}++#[derive(Debug, Clone, uniffi::Enum)]+pub enum Sender {+ SelfUser,+ Other,+}++impl Sender {+ fn as_str(&self) -> &'static str {+ match self {+ Sender::SelfUser => "self",+ Sender::Other => "other",+ }+ }+}++#[derive(Debug, Clone, uniffi::Enum)]+pub enum AttachmentKind {+ Image,+ Document,+}++impl From<AttachmentKind> for core::AttachmentKind {+ fn from(value: AttachmentKind) -> Self {+ match value {+ AttachmentKind::Image => core::AttachmentKind::Image,+ AttachmentKind::Document => core::AttachmentKind::Document,+ }+ }+}++impl From<core::AttachmentKind> for AttachmentKind {+ fn from(value: core::AttachmentKind) -> Self {+ match value {+ core::AttachmentKind::Image => AttachmentKind::Image,+ core::AttachmentKind::Document => AttachmentKind::Document,+ }+ }+}++#[derive(Debug, Clone, uniffi::Record)]+pub struct AttachmentMeta {+ pub id: String,+ pub kind: AttachmentKind,+ pub size: i64,+ pub name: String,+}++impl From<AttachmentMeta> for core::AttachmentMeta {+ fn from(value: AttachmentMeta) -> Self {+ core::AttachmentMeta {+ id: value.id,+ kind: value.kind.into(),+ size: value.size,+ name: value.name,+ }+ }+}++impl From<core::AttachmentMeta> for AttachmentMeta {+ fn from(value: core::AttachmentMeta) -> Self {+ AttachmentMeta {+ id: value.id,+ kind: value.kind.into(),+ size: value.size,+ name: value.name,+ }+ }+}++#[derive(Debug, Clone, uniffi::Record)]+pub struct Message {+ pub uuid: String,+ pub session_uuid: String,+ pub parent_message_uuid: Option<String>,+ pub sender: Sender,+ pub text: String,+ pub attachments: Vec<AttachmentMeta>,+ pub created_at_us: i64,+ pub deleted_at_us: Option<i64>,+}++#[derive(uniffi::Object)]+pub struct LlmChatDb {+ inner: core::LlmChatDb<core::SqliteBackend>,+}++fn to_session(session: core::Session) -> Session {+ Session {+ uuid: session.uuid.to_string(),+ title: session.title,+ created_at_us: session.created_at,+ updated_at_us: session.updated_at,+ remote_id: session.remote_id,+ needs_sync: session.needs_sync,+ deleted_at_us: session.deleted_at,+ }+}++fn to_message(message: core::Message) -> Message {+ Message {+ uuid: message.uuid.to_string(),+ session_uuid: message.session_uuid.to_string(),+ parent_message_uuid: message.parent_message_uuid.map(|v| v.to_string()),+ sender: match message.sender {+ core::Sender::SelfUser => Sender::SelfUser,+ core::Sender::Other => Sender::Other,+ },+ text: message.text,+ attachments: message.attachments.into_iter().map(Into::into).collect(),+ created_at_us: message.created_at,+ deleted_at_us: message.deleted_at,+ }+}++#[uniffi::export]+impl LlmChatDb {+ #[uniffi::constructor]+ pub fn open(main_db_path: String, attachments_db_path: String, key: Vec<u8>) -> Result<Self, DbError> {+ let inner = core::LlmChatDb::open_sqlite_with_defaults(main_db_path, attachments_db_path, key)?;+ Ok(Self { inner })+ }++ pub fn create_session(&self, title: String) -> Result<Session, DbError> {+ Ok(to_session(self.inner.create_session(&title)?))+ }++ pub fn list_sessions(&self) -> Result<Vec<Session>, DbError> {+ Ok(self.inner.list_sessions()?.into_iter().map(to_session).collect())+ }++ pub fn get_session(&self, uuid: String) -> Result<Option<Session>, DbError> {+ let uuid = Uuid::parse_str(&uuid).map_err(|e| DbError::Message(e.to_string()))?;+ Ok(self.inner.get_session(uuid)?.map(to_session))+ }++ pub fn delete_session(&self, uuid: String) -> Result<(), DbError> {+ let uuid = Uuid::parse_str(&uuid).map_err(|e| DbError::Message(e.to_string()))?;+ Ok(self.inner.delete_session(uuid)?)+ }++ pub fn insert_message(+ &self,+ session_uuid: String,+ sender: Sender,+ text: String,+ parent_message_uuid: Option<String>,+ attachments: Vec<AttachmentMeta>,+ ) -> Result<Message, DbError> {+ let session_uuid = Uuid::parse_str(&session_uuid).map_err(|e| DbError::Message(e.to_string()))?;+ let parent = parent_message_uuid+ .map(|v| Uuid::parse_str(&v))+ .transpose()+ .map_err(|e| DbError::Message(e.to_string()))?;++ let message = self.inner.insert_message(+ session_uuid,+ sender.as_str(),+ &text,+ parent,+ attachments.into_iter().map(Into::into).collect(),+ )?;+ Ok(to_message(message))+ }++ pub fn get_messages(&self, session_uuid: String) -> Result<Vec<Message>, DbError> {+ let session_uuid = Uuid::parse_str(&session_uuid).map_err(|e| DbError::Message(e.to_string()))?;+ Ok(self.inner.get_messages(session_uuid)?.into_iter().map(to_message).collect())+ }++ pub fn update_message_text(&self, uuid: String, text: String) -> Result<(), DbError> {+ let uuid = Uuid::parse_str(&uuid).map_err(|e| DbError::Message(e.to_string()))?;+ Ok(self.inner.update_message_text(uuid, &text)?)+ }+}diff --git a/rust/llmchat_db_uniffi/src/api.udl b/rust/llmchat_db_uniffi/src/api.udlnew file mode 100644index 0000000000..a905f63b51--- /dev/null+++ b/rust/llmchat_db_uniffi/src/api.udl@@ -0,0 +1,70 @@+[Error]+interface DbError {+ Message(string message);+};++enum Sender {+ "SelfUser",+ "Other"+};++enum AttachmentKind {+ "Image",+ "Document"+};++dictionary AttachmentMeta {+ string id;+ AttachmentKind kind;+ i64 size;+ string name;+};++dictionary Session {+ string uuid;+ string title;+ i64 created_at_us;+ i64 updated_at_us;+ string? remote_id;+ boolean needs_sync;+ i64? deleted_at_us;+};++dictionary Message {+ string uuid;+ string session_uuid;+ string? parent_message_uuid;+ Sender sender;+ string text;+ sequence<AttachmentMeta> attachments;+ i64 created_at_us;+ i64? deleted_at_us;+};++namespace llmchat_db_uniffi {+ interface LlmChatDb {+ [Constructor, Throws=DbError]+ LlmChatDb(string main_db_path, string attachments_db_path, sequence<u8> key);++ [Throws=DbError]+ Session create_session(string title);++ [Throws=DbError]+ sequence<Session> list_sessions();++ [Throws=DbError]+ Session? get_session(string uuid);++ [Throws=DbError]+ void delete_session(string uuid);++ [Throws=DbError]+ Message insert_message(string session_uuid, Sender sender, string text, string? parent_message_uuid, sequence<AttachmentMeta> attachments);++ [Throws=DbError]+ sequence<Message> get_messages(string session_uuid);++ [Throws=DbError]+ void update_message_text(string uuid, string text);+ };+};diff --git a/rust/llmchat_db_uniffi/src/lib.rs b/rust/llmchat_db_uniffi/src/lib.rsnew file mode 100644index 0000000000..11e4194664--- /dev/null+++ b/rust/llmchat_db_uniffi/src/lib.rs@@ -0,0 +1,7 @@+#![allow(unexpected_cfgs)]++mod api;++uniffi::setup_scaffolding!("llmchat_db_uniffi");++pub use api::*;diff --git a/rust/llmchat_db_uniffi/uniffi.toml b/rust/llmchat_db_uniffi/uniffi.tomlnew file mode 100644index 0000000000..728f5e9c61--- /dev/null+++ b/rust/llmchat_db_uniffi/uniffi.toml@@ -0,0 +1,8 @@+[bindings.swift]+link_frameworks = ["Foundation"]++[bindings.kotlin]+package_name = "io.ente.labs.llmchat_db"+cdylib_name = "llmchat_db_uniffi"+android = true+kotlin_target_version = "1.9.0"