Skip to content

armgit / ente

Public Imported from GitHub
0

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

rename db crate refs to ensu

Prateek Sunal83ea60ac93db
diff --git a/rust/ensu/README.md b/rust/ensu/README.md
index 17c1831681..c02377b078 100644
--- a/rust/ensu/README.md
+++ b/rust/ensu/README.md
@@ -4,8 +4,8 @@ This directory contains the Rust crates for the Ensu LLM chat stack.
## Crates
-- `db/` (`llmchat-db`) β€” local chat database.
-- `sync/` (`ensu-sync`) β€” sync engine (uses `llmchat-db`).
+- `db/` (`ensu-db`) β€” local chat database.
+- `sync/` (`ensu-sync`) β€” sync engine (uses `ensu-db`).
- `inference/` (`inference_rs`) β€” inference runtime.
## UniFFI bindings
diff --git a/rust/ensu/db/Cargo.lock b/rust/ensu/db/Cargo.lock
index f924e68f14..c7fef105ae 100644
--- a/rust/ensu/db/Cargo.lock
+++ b/rust/ensu/db/Cargo.lock
@@ -277,6 +277,20 @@ dependencies = [
"cfg-if",
]
+[[package]]
+name = "ensu-db"
+version = "0.1.0"
+dependencies = [
+ "ente-core",
+ "rusqlite",
+ "serde",
+ "serde_json",
+ "tempfile",
+ "thiserror",
+ "uuid",
+ "zeroize",
+]
+
[[package]]
name = "ente-core"
version = "0.0.1"
@@ -774,20 +788,6 @@ 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",
- "tempfile",
- "thiserror",
- "uuid",
- "zeroize",
-]
-
[[package]]
name = "log"
version = "0.4.29"
diff --git a/rust/ensu/db/Cargo.toml b/rust/ensu/db/Cargo.toml
index 6f52b2b850..331bebbf17 100644
--- a/rust/ensu/db/Cargo.toml
+++ b/rust/ensu/db/Cargo.toml
@@ -1,5 +1,5 @@
[package]
-name = "llmchat-db"
+name = "ensu-db"
version = "0.1.0"
edition = "2024"
diff --git a/rust/ensu/sync/Cargo.lock b/rust/ensu/sync/Cargo.lock
index e343ddd7df..ea5ec87d45 100644
--- a/rust/ensu/sync/Cargo.lock
+++ b/rust/ensu/sync/Cargo.lock
@@ -594,14 +594,27 @@ dependencies = [
"cfg-if",
]
+[[package]]
+name = "ensu-db"
+version = "0.1.0"
+dependencies = [
+ "ente-core",
+ "rusqlite",
+ "serde",
+ "serde_json",
+ "thiserror 2.0.18",
+ "uuid",
+ "zeroize",
+]
+
[[package]]
name = "ensu-sync"
version = "0.1.0"
dependencies = [
+ "ensu-db",
"ente-core",
"hkdf",
"httpmock",
- "llmchat-db",
"reqwest",
"serde",
"serde_json",
@@ -1363,19 +1376,6 @@ 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 2.0.18",
- "uuid",
- "zeroize",
-]
-
[[package]]
name = "lock_api"
version = "0.4.14"
diff --git a/rust/ensu/sync/Cargo.toml b/rust/ensu/sync/Cargo.toml
index 15438add22..d02d9ab7b2 100644
--- a/rust/ensu/sync/Cargo.toml
+++ b/rust/ensu/sync/Cargo.toml
@@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2024"
[dependencies]
-llmchat-db = { path = "../db" }
+ensu-db = { path = "../db" }
ente-core = { path = "../../core" }
reqwest = { version = "0.12", default-features = false, features = ["json", "blocking", "http2", "charset", "system-proxy", "rustls-tls-native-roots"] }
serde = { version = "1", features = ["derive"] }
diff --git a/rust/ensu/sync/src/conflict.rs b/rust/ensu/sync/src/conflict.rs
index dc3a3e4240..860491cea6 100644
--- a/rust/ensu/sync/src/conflict.rs
+++ b/rust/ensu/sync/src/conflict.rs
@@ -1,6 +1,6 @@
use std::collections::{HashMap, HashSet};
-use llmchat_db::{AttachmentMeta, Message, Sender};
+use ensu_db::{AttachmentMeta, Message, Sender};
use uuid::Uuid;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -167,7 +167,7 @@ fn attachments_signature(attachments: &[AttachmentMeta]) -> Vec<String> {
#[cfg(test)]
mod tests {
use super::*;
- use llmchat_db::{AttachmentKind, AttachmentMeta, Message, Sender};
+ use ensu_db::{AttachmentKind, AttachmentMeta, Message, Sender};
use uuid::Uuid;
#[test]
diff --git a/rust/ensu/sync/src/crypto.rs b/rust/ensu/sync/src/crypto.rs
index 30b3c57e46..275c25be86 100644
--- a/rust/ensu/sync/src/crypto.rs
+++ b/rust/ensu/sync/src/crypto.rs
@@ -63,7 +63,7 @@ pub fn encrypt_attachment_bytes(
session_uuid: Uuid,
) -> Result<Vec<u8>, SyncError> {
let key = derive_attachment_key(chat_key, session_uuid)?;
- Ok(llmchat_db::crypto::encrypt_blob(plaintext, &key)?)
+ Ok(ensu_db::crypto::encrypt_blob(plaintext, &key)?)
}
pub fn decrypt_attachment_bytes(
@@ -72,5 +72,5 @@ pub fn decrypt_attachment_bytes(
session_uuid: Uuid,
) -> Result<Vec<u8>, SyncError> {
let key = derive_attachment_key(chat_key, session_uuid)?;
- Ok(llmchat_db::crypto::decrypt_blob(ciphertext, &key)?)
+ Ok(ensu_db::crypto::decrypt_blob(ciphertext, &key)?)
}
diff --git a/rust/ensu/sync/src/errors.rs b/rust/ensu/sync/src/errors.rs
index aa04f3248d..2e185f718d 100644
--- a/rust/ensu/sync/src/errors.rs
+++ b/rust/ensu/sync/src/errors.rs
@@ -7,7 +7,7 @@ pub enum SyncError {
#[error("unauthorized")]
Unauthorized,
#[error("db error: {0}")]
- Db(#[from] llmchat_db::Error),
+ Db(#[from] ensu_db::Error),
#[error("crypto error: {0}")]
Crypto(String),
#[error("http {status}: {message}")]
diff --git a/rust/ensu/sync/src/models.rs b/rust/ensu/sync/src/models.rs
index 34c36e0dee..91e7f3541c 100644
--- a/rust/ensu/sync/src/models.rs
+++ b/rust/ensu/sync/src/models.rs
@@ -1,7 +1,7 @@
use serde::{Deserialize, Serialize};
use crate::diff_cursor::SyncCursor;
-use llmchat_db::AttachmentKind;
+use ensu_db::AttachmentKind;
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
diff --git a/rust/ensu/sync/src/sync.rs b/rust/ensu/sync/src/sync.rs
index 754d3fb73a..744a9dc808 100644
--- a/rust/ensu/sync/src/sync.rs
+++ b/rust/ensu/sync/src/sync.rs
@@ -5,12 +5,12 @@ use std::sync::atomic::{AtomicBool, Ordering};
use zeroize::Zeroizing;
-use ente_core::crypto::keys;
-use llmchat_db::{
+use ensu_db::{
AttachmentKind, AttachmentMeta, AttachmentStore, Clock, EntityType, FsAttachmentStore,
LlmChatDb, Message, Sender, Session, SqliteBackend, SyncEntityState, SyncStateDb, SystemClock,
UploadState,
};
+use ente_core::crypto::keys;
use uuid::Uuid;
use crate::conflict::{
@@ -130,9 +130,9 @@ impl SyncEngine {
_meta_dir: String,
plaintext_dir: Option<String>,
) -> Result<Self, SyncError> {
- llmchat_db::traits::ensure_directory(&attachments_dir)?;
+ ensu_db::traits::ensure_directory(&attachments_dir)?;
if let Some(ref dir) = plaintext_dir {
- let _ = llmchat_db::traits::ensure_directory(dir);
+ let _ = ensu_db::traits::ensure_directory(dir);
}
let db = LlmChatDb::open_sqlite_with_defaults(main_db_path, sync_db_path.clone(), db_key)?;
@@ -160,7 +160,7 @@ impl SyncEngine {
if auth.auth_token.trim().is_empty() {
return Err(SyncError::NotLoggedIn);
}
- if auth.master_key.len() != llmchat_db::crypto::KEY_BYTES {
+ if auth.master_key.len() != ensu_db::crypto::KEY_BYTES {
return Err(SyncError::Crypto("invalid master key length".to_string()));
}
@@ -212,7 +212,7 @@ impl SyncEngine {
if auth.auth_token.trim().is_empty() {
return Err(SyncError::NotLoggedIn);
}
- if auth.master_key.len() != llmchat_db::crypto::KEY_BYTES {
+ if auth.master_key.len() != ensu_db::crypto::KEY_BYTES {
return Err(SyncError::Crypto("invalid master key length".to_string()));
}
@@ -348,7 +348,7 @@ impl SyncEngine {
return Ok(());
}
- let offline_db = llmchat_db::ChatDb::open_sqlite_with_defaults(
+ let offline_db = ensu_db::ChatDb::open_sqlite_with_defaults(
offline_db_path.clone(),
offline_db_key.clone(),
)?;
@@ -391,7 +391,7 @@ impl SyncEngine {
if auth.auth_token.trim().is_empty() {
return Err(SyncError::NotLoggedIn);
}
- if auth.master_key.len() != llmchat_db::crypto::KEY_BYTES {
+ if auth.master_key.len() != ensu_db::crypto::KEY_BYTES {
return Err(SyncError::Crypto("invalid master key length".to_string()));
}
@@ -465,7 +465,7 @@ impl SyncEngine {
if auth.auth_token.trim().is_empty() {
return Err(SyncError::NotLoggedIn);
}
- if auth.master_key.len() != llmchat_db::crypto::KEY_BYTES {
+ if auth.master_key.len() != ensu_db::crypto::KEY_BYTES {
return Err(SyncError::Crypto("invalid master key length".to_string()));
}
@@ -921,7 +921,7 @@ impl SyncEngine {
Ok(())
}
- fn open_offline_db(&self) -> Result<Option<llmchat_db::ChatDb<SqliteBackend>>, SyncError> {
+ fn open_offline_db(&self) -> Result<Option<ensu_db::ChatDb<SqliteBackend>>, SyncError> {
let config = match self.offline_db.lock() {
Ok(guard) => guard.clone(),
Err(_) => None,
@@ -932,7 +932,7 @@ impl SyncEngine {
if config.path.trim().is_empty() {
return Ok(None);
}
- let db = llmchat_db::ChatDb::open_sqlite_with_defaults(config.path, config.key)?;
+ let db = ensu_db::ChatDb::open_sqlite_with_defaults(config.path, config.key)?;
Ok(Some(db))
}
@@ -1582,7 +1582,7 @@ pub fn fetch_chat_key(auth: SyncAuth, sync_db_path: String) -> Result<Vec<u8>, S
if auth.auth_token.trim().is_empty() {
return Err(SyncError::NotLoggedIn);
}
- if auth.master_key.len() != llmchat_db::crypto::KEY_BYTES {
+ if auth.master_key.len() != ensu_db::crypto::KEY_BYTES {
return Err(SyncError::Crypto("invalid master key length".to_string()));
}
@@ -1713,7 +1713,7 @@ fn encode_client_metadata(
chat_key: &[u8],
) -> Result<String, SyncError> {
let created_at_value = if created_at > 0 {
- let encrypted = llmchat_db::crypto::encrypt_json_field(&created_at.to_string(), chat_key)
+ let encrypted = ensu_db::crypto::encrypt_json_field(&created_at.to_string(), chat_key)
.map_err(|err| SyncError::Crypto(err.to_string()))?;
Some(serde_json::Value::String(encrypted))
} else {
@@ -1740,8 +1740,7 @@ fn decode_client_created_at(value: &str, chat_key: &[u8]) -> Option<i64> {
let parsed = match created_at_value {
serde_json::Value::Number(number) => number.as_i64(),
serde_json::Value::String(raw) => {
- let decrypted =
- llmchat_db::crypto::decrypt_json_field(&raw, chat_key).unwrap_or(raw);
+ let decrypted = ensu_db::crypto::decrypt_json_field(&raw, chat_key).unwrap_or(raw);
decrypted.parse::<i64>().ok()
}
_ => None,
@@ -1749,8 +1748,8 @@ fn decode_client_created_at(value: &str, chat_key: &[u8]) -> Option<i64> {
return parsed.filter(|created_at| *created_at > 0);
}
- let decrypted = llmchat_db::crypto::decrypt_json_field(value, chat_key)
- .unwrap_or_else(|_| value.to_string());
+ let decrypted =
+ ensu_db::crypto::decrypt_json_field(value, chat_key).unwrap_or_else(|_| value.to_string());
decrypted
.parse::<i64>()
.ok()
@@ -1775,7 +1774,7 @@ fn encode_attachment_metadata(
message_uuid: Uuid,
chat_key: &[u8],
) -> Result<String, SyncError> {
- let encrypted_name = llmchat_db::crypto::encrypt_json_field(&attachment.name, chat_key)
+ let encrypted_name = ensu_db::crypto::encrypt_json_field(&attachment.name, chat_key)
.map_err(|err| SyncError::Crypto(err.to_string()))?;
let payload = AttachmentClientMetadata {
client_id: format!("{}:{}", message_uuid, attachment.id),
@@ -1797,7 +1796,7 @@ fn decode_attachment_metadata(
let encrypted_name = payload.encrypted_name.ok_or_else(|| {
SyncError::InvalidResponse("missing attachment encryptedName".to_string())
})?;
- let name = llmchat_db::crypto::decrypt_json_field(&encrypted_name, chat_key)
+ let name = ensu_db::crypto::decrypt_json_field(&encrypted_name, chat_key)
.map_err(|err| SyncError::Crypto(err.to_string()))?;
let kind = payload.kind.unwrap_or_else(|| infer_kind(&name));
let local_id = payload
@@ -1820,7 +1819,7 @@ fn decode_attachment_metadata(
.encrypted_name
.as_ref()
.ok_or_else(|| SyncError::InvalidResponse("missing attachment metadata".to_string()))?;
- let name = llmchat_db::crypto::decrypt_json_field(encrypted_name, chat_key)
+ let name = ensu_db::crypto::decrypt_json_field(encrypted_name, chat_key)
.map_err(|err| SyncError::Crypto(err.to_string()))?;
let kind = attachment.kind.unwrap_or_else(|| infer_kind(&name));
let client_id = attachment.id.clone();
diff --git a/rust/ensu/sync/tests/sync_integration.rs b/rust/ensu/sync/tests/sync_integration.rs
index da70d75b51..725f78e0bd 100644
--- a/rust/ensu/sync/tests/sync_integration.rs
+++ b/rust/ensu/sync/tests/sync_integration.rs
@@ -1,3 +1,5 @@
+use ensu_db::LlmChatDb;
+use ensu_db::crypto::KEY_BYTES;
use ensu_sync::SyncAuth;
use ensu_sync::SyncEngine;
use ensu_sync::crypto::{encrypt_chat_key, encrypt_payload};
@@ -7,8 +9,6 @@ use ensu_sync::models::{
};
use httpmock::Method::{DELETE, GET, POST};
use httpmock::MockServer;
-use llmchat_db::LlmChatDb;
-use llmchat_db::crypto::KEY_BYTES;
use tempfile::TempDir;
use uuid::Uuid;
use zeroize::Zeroizing;
diff --git a/rust/uniffi/ensu/db/Cargo.lock b/rust/uniffi/ensu/db/Cargo.lock
index 168680a512..30aa7ce90a 100644
--- a/rust/uniffi/ensu/db/Cargo.lock
+++ b/rust/uniffi/ensu/db/Cargo.lock
@@ -345,7 +345,7 @@ dependencies = [
name = "db"
version = "0.1.0"
dependencies = [
- "llmchat-db",
+ "ensu-db",
"serde",
"thiserror",
"uniffi",
@@ -383,6 +383,19 @@ dependencies = [
"cfg-if",
]
+[[package]]
+name = "ensu-db"
+version = "0.1.0"
+dependencies = [
+ "ente-core",
+ "rusqlite",
+ "serde",
+ "serde_json",
+ "thiserror",
+ "uuid",
+ "zeroize",
+]
+
[[package]]
name = "ente-core"
version = "0.0.1"
@@ -914,19 +927,6 @@ 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 = "log"
version = "0.4.29"
diff --git a/rust/uniffi/ensu/db/Cargo.toml b/rust/uniffi/ensu/db/Cargo.toml
index ed293ddf8f..a1f04674dd 100644
--- a/rust/uniffi/ensu/db/Cargo.toml
+++ b/rust/uniffi/ensu/db/Cargo.toml
@@ -8,7 +8,7 @@ name = "db"
crate-type = ["staticlib", "cdylib"]
[dependencies]
-llmchat-db = { path = "../../../ensu/db" }
+ensu-db = { path = "../../../ensu/db" }
serde = { version = "1", features = ["derive"] }
thiserror = "2"
uniffi = { version = "0.31.0" }
diff --git a/rust/uniffi/ensu/db/src/api.rs b/rust/uniffi/ensu/db/src/api.rs
index 03ae685aa0..42de99a532 100644
--- a/rust/uniffi/ensu/db/src/api.rs
+++ b/rust/uniffi/ensu/db/src/api.rs
@@ -1,4 +1,4 @@
-use llmchat_db as core;
+use ensu_db as core;
use thiserror::Error;
use uuid::Uuid;
diff --git a/rust/uniffi/ensu/db/uniffi.toml b/rust/uniffi/ensu/db/uniffi.toml
index a4ef25dc45..11d4195aa3 100644
--- a/rust/uniffi/ensu/db/uniffi.toml
+++ b/rust/uniffi/ensu/db/uniffi.toml
@@ -2,7 +2,7 @@
link_frameworks = ["Foundation"]
[bindings.kotlin]
-package_name = "io.ente.labs.llmchat_db"
+package_name = "io.ente.labs.ensu_db"
cdylib_name = "db"
android = true
kotlin_target_version = "1.9.0"
diff --git a/rust/uniffi/ensu/sync/Cargo.lock b/rust/uniffi/ensu/sync/Cargo.lock
index e76b2d6e0f..7dad93e1d2 100644
--- a/rust/uniffi/ensu/sync/Cargo.lock
+++ b/rust/uniffi/ensu/sync/Cargo.lock
@@ -372,13 +372,26 @@ dependencies = [
"cfg-if",
]
+[[package]]
+name = "ensu-db"
+version = "0.1.0"
+dependencies = [
+ "ente-core",
+ "rusqlite",
+ "serde",
+ "serde_json",
+ "thiserror",
+ "uuid",
+ "zeroize",
+]
+
[[package]]
name = "ensu-sync"
version = "0.1.0"
dependencies = [
+ "ensu-db",
"ente-core",
"hkdf",
- "llmchat-db",
"reqwest",
"serde",
"serde_json",
@@ -947,19 +960,6 @@ 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 = "log"
version = "0.4.29"