π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
rename sync to ensu
Prateek Sunald654b2cc69ca
diff --git a/rust/ensu/README.md b/rust/ensu/README.mdindex 82f53e1861..17c1831681 100644--- a/rust/ensu/README.md+++ b/rust/ensu/README.md@@ -5,7 +5,7 @@ This directory contains the Rust crates for the Ensu LLM chat stack.## Crates- `db/` (`llmchat-db`) β local chat database.-- `sync/` (`llmchat-sync`) β sync engine (uses `llmchat-db`).+- `sync/` (`ensu-sync`) β sync engine (uses `llmchat-db`).- `inference/` (`inference_rs`) β inference runtime.## UniFFI bindingsdiff --git a/rust/ensu/sync/Cargo.lock b/rust/ensu/sync/Cargo.lockindex a3834418c9..e343ddd7df 100644--- a/rust/ensu/sync/Cargo.lock+++ b/rust/ensu/sync/Cargo.lock@@ -594,6 +594,24 @@ dependencies = ["cfg-if",]+[[package]]+name = "ensu-sync"+version = "0.1.0"+dependencies = [+ "ente-core",+ "hkdf",+ "httpmock",+ "llmchat-db",+ "reqwest",+ "serde",+ "serde_json",+ "sha2",+ "tempfile",+ "thiserror 2.0.18",+ "uuid",+ "zeroize",+]+[[package]]name = "ente-core"version = "0.0.1"@@ -1358,24 +1376,6 @@ dependencies = ["zeroize",]-[[package]]-name = "llmchat-sync"-version = "0.1.0"-dependencies = [- "ente-core",- "hkdf",- "httpmock",- "llmchat-db",- "reqwest",- "serde",- "serde_json",- "sha2",- "tempfile",- "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.tomlindex aff7a8a8d8..15438add22 100644--- a/rust/ensu/sync/Cargo.toml+++ b/rust/ensu/sync/Cargo.toml@@ -1,5 +1,5 @@[package]-name = "llmchat-sync"+name = "ensu-sync"version = "0.1.0"edition = "2024"diff --git a/rust/ensu/sync/src/sync.rs b/rust/ensu/sync/src/sync.rsindex 754d3fb73a..46d81b6ec9 100644--- a/rust/ensu/sync/src/sync.rs+++ b/rust/ensu/sync/src/sync.rs@@ -417,7 +417,7 @@ impl SyncEngine {return Ok(MigrationState::NotNeeded);}- let remote = http.get_json_optional::<ChatKeyPayload>("/llmchat/chat/key", &[]);+ let remote = http.get_json_optional::<ChatKeyPayload>("/ensu/chat/key", &[]);match remote {Ok(Some(_)) => Ok(MigrationState::InProgress),Ok(None) => Ok(MigrationState::InProgress),@@ -513,7 +513,7 @@ impl SyncEngine {fallback}};- let mut url = format!("{}/llmchat/chat/attachment/{}", base_url, remote_id);+ let mut url = format!("{}/ensu/chat/attachment/{}", base_url, remote_id);let bytes = match http.get_bytes(&url) {Ok(bytes) => bytes,Err(SyncError::Http { status: 404, .. }) => {@@ -524,7 +524,7 @@ impl SyncEngine {}if let Some(updated) = self.db.get_attachment_remote_id(&attachment_id)? {remote_id = updated;- url = format!("{}/llmchat/chat/attachment/{}", base_url, remote_id);+ url = format!("{}/ensu/chat/attachment/{}", base_url, remote_id);}http.get_bytes(&url)?}@@ -565,7 +565,7 @@ impl SyncEngine {("sinceId", cursor.since_id.clone()),("limit", self.diff_limit.to_string()),];- let response: DiffResponse = http.get_json("/llmchat/chat/diff", &query)?;+ let response: DiffResponse = http.get_json("/ensu/chat/diff", &query)?;self.apply_diff(&response, chat_key, result)?;@@ -975,7 +975,7 @@ impl SyncEngine {let deleted_sessions = self.db.get_deleted_sessions()?;for (uuid, _deleted_at) in deleted_sessions {if let Some(remote_id) = self.sync_state.get_session_remote_id(uuid)? {- http.delete("/llmchat/chat/session", &[("id", remote_id)])?;+ http.delete("/ensu/chat/session", &[("id", remote_id)])?;let _ = self.sync_state.delete_session_state(uuid);}let _ = self.db.delete_attachment_tracking_for_session(uuid);@@ -985,7 +985,7 @@ impl SyncEngine {let deleted_messages = self.db.get_deleted_messages()?;for (uuid, _deleted_at) in deleted_messages {if let Some(remote_id) = self.sync_state.get_message_remote_id(uuid)? {- http.delete("/llmchat/chat/message", &[("id", remote_id)])?;+ http.delete("/ensu/chat/message", &[("id", remote_id)])?;let _ = self.sync_state.delete_message_state(uuid);}let _ = self.db.delete_attachment_tracking_for_message(uuid);@@ -1092,7 +1092,7 @@ impl SyncEngine {client_metadata: Some(client_metadata),};let response: UpsertSessionResponse =- http.post_json("/llmchat/chat/session", &session_request)?;+ http.post_json("/ensu/chat/session", &session_request)?;let remote_id = response.session_uuid;self.sync_state.set_session_state(session.uuid, Some(&remote_id), response.updated_at)?;@@ -1171,7 +1171,7 @@ impl SyncEngine {client_metadata: Some(client_metadata),};let response: UpsertMessageResponse =- http.post_json("/llmchat/chat/message", &message_request)?;+ http.post_json("/ensu/chat/message", &message_request)?;self.sync_state.set_message_state(message.uuid,Some(&response.message_uuid),@@ -1364,12 +1364,12 @@ impl SyncEngine {}};- let status =- match http.head_status(&format!("/llmchat/chat/attachment/{}", remote_id)) {- Ok(status) => status,- Err(SyncError::Unauthorized) => return Err(SyncError::Unauthorized),- Err(_) => continue,- };+ let status = match http.head_status(&format!("/ensu/chat/attachment/{}", remote_id))+ {+ Ok(status) => status,+ Err(SyncError::Unauthorized) => return Err(SyncError::Unauthorized),+ Err(_) => continue,+ };if status == 404 {let _ = self.db.upsert_pending_attachment(@@ -1403,7 +1403,7 @@ impl SyncEngine {content_md5: None,};let upload_url = http.post_json::<UploadUrlResponse, _>(- "/llmchat/chat/attachment/upload-url?force=true",+ "/ensu/chat/attachment/upload-url?force=true",&request,)?;self.db@@ -1450,9 +1450,9 @@ impl SyncEngine {};let upload_path = if force_uploads.contains(&row.attachment_id) {- "/llmchat/chat/attachment/upload-url?force=true".to_string()+ "/ensu/chat/attachment/upload-url?force=true".to_string()} else {- "/llmchat/chat/attachment/upload-url".to_string()+ "/ensu/chat/attachment/upload-url".to_string()};let upload_url = match http.post_json::<UploadUrlResponse, _>(&upload_path, &request) {@@ -1646,7 +1646,7 @@ fn get_or_create_chat_key_with_state(return Ok((key, ChatKeyStatus::Cached));}- let remote = http.get_json_optional::<ChatKeyPayload>("/llmchat/chat/key", &[]);+ let remote = http.get_json_optional::<ChatKeyPayload>("/ensu/chat/key", &[]);let remote = match remote {Ok(value) => value,Err(SyncError::Http {@@ -1674,13 +1674,13 @@ fn get_or_create_chat_key_with_state(let encrypted = encrypt_chat_key(&chat_key, master_key)?;let payload = ChatKeyPayload::from_encrypted(&encrypted);- match http.post_empty("/llmchat/chat/key", &payload) {+ match http.post_empty("/ensu/chat/key", &payload) {Ok(()) => {save_chat_key_to_meta(sync_state, &payload)?;Ok((chat_key, ChatKeyStatus::Created))}Err(SyncError::Http { status: 409, .. }) => {- let existing = http.get_json_optional::<ChatKeyPayload>("/llmchat/chat/key", &[])?;+ let existing = http.get_json_optional::<ChatKeyPayload>("/ensu/chat/key", &[])?;let payload = existing.ok_or_else(|| SyncError::InvalidResponse("chat key already exists".to_string()))?;let encrypted = payload.encrypted_value().ok_or_else(|| {diff --git a/rust/ensu/sync/tests/sync_integration.rs b/rust/ensu/sync/tests/sync_integration.rsindex b619197323..44214ff68c 100644--- a/rust/ensu/sync/tests/sync_integration.rs+++ b/rust/ensu/sync/tests/sync_integration.rs@@ -1,14 +1,14 @@+use ensu_sync::SyncAuth;+use ensu_sync::SyncEngine;+use ensu_sync::crypto::{encrypt_chat_key, encrypt_payload};+use ensu_sync::models::{+ ChatKeyPayload, DiffResponse, DiffTombstones, MessagePayload, MessageTombstone, RemoteMessage,+ RemoteSession, SessionPayload,+};use httpmock::Method::{DELETE, GET, POST};use httpmock::MockServer;use llmchat_db::LlmChatDb;use llmchat_db::crypto::KEY_BYTES;-use llmchat_sync::SyncAuth;-use llmchat_sync::SyncEngine;-use llmchat_sync::crypto::{encrypt_chat_key, encrypt_payload};-use llmchat_sync::models::{- ChatKeyPayload, DiffResponse, DiffTombstones, MessagePayload, MessageTombstone, RemoteMessage,- RemoteSession, SessionPayload,-};use tempfile::TempDir;use uuid::Uuid;use zeroize::Zeroizing;@@ -55,7 +55,7 @@ fn mock_chat_key(server: &MockServer, master_key: &[u8], chat_key: &[u8]) {let encrypted = encrypt_chat_key(chat_key, master_key).expect("encrypt chat key");let payload = ChatKeyPayload::from_encrypted(&encrypted);server.mock(|when, then| {- when.method(GET).path("/llmchat/chat/key");+ when.method(GET).path("/ensu/chat/key");then.status(200).json_body_obj(&payload);});}@@ -69,7 +69,7 @@ fn mock_empty_diff(server: &MockServer, timestamp: i64) {timestamp: Some(timestamp),};server.mock(|when, then| {- when.method(GET).path("/llmchat/chat/diff");+ when.method(GET).path("/ensu/chat/diff");then.status(200).json_body_obj(&diff);});}@@ -136,7 +136,7 @@ fn pull_applies_remote_sessions_and_messages() {};server.mock(|when, then| {- when.method(GET).path("/llmchat/chat/diff");+ when.method(GET).path("/ensu/chat/diff");then.status(200).json_body_obj(&diff);});@@ -200,12 +200,12 @@ fn push_only_needs_sync_messages() {mock_empty_diff(&server, 10);let session_mock = server.mock(|when, then| {- when.method(POST).path("/llmchat/chat/session");+ when.method(POST).path("/ensu/chat/session");then.status(200).json_body_obj(&serde_json::json!({}));});let message_mock = server.mock(|when, then| {- when.method(POST).path("/llmchat/chat/message");+ when.method(POST).path("/ensu/chat/message");then.status(200).json_body_obj(&serde_json::json!({}));});@@ -287,12 +287,12 @@ fn tombstone_removes_messages() {};server.mock(|when, then| {- when.method(GET).path("/llmchat/chat/diff");+ when.method(GET).path("/ensu/chat/diff");then.status(200).json_body_obj(&diff);});server.mock(|when, then| {- when.method(DELETE).path("/llmchat/chat/message");+ when.method(DELETE).path("/ensu/chat/message");then.status(200).json_body_obj(&serde_json::json!({}));});diff --git a/rust/uniffi/ensu/sync/Cargo.lock b/rust/uniffi/ensu/sync/Cargo.lockindex 2920ca9bfc..e76b2d6e0f 100644--- a/rust/uniffi/ensu/sync/Cargo.lock+++ b/rust/uniffi/ensu/sync/Cargo.lock@@ -372,6 +372,22 @@ dependencies = ["cfg-if",]+[[package]]+name = "ensu-sync"+version = "0.1.0"+dependencies = [+ "ente-core",+ "hkdf",+ "llmchat-db",+ "reqwest",+ "serde",+ "serde_json",+ "sha2",+ "thiserror",+ "uuid",+ "zeroize",+]+[[package]]name = "ente-core"version = "0.0.1"@@ -944,22 +960,6 @@ dependencies = ["zeroize",]-[[package]]-name = "llmchat-sync"-version = "0.1.0"-dependencies = [- "ente-core",- "hkdf",- "llmchat-db",- "reqwest",- "serde",- "serde_json",- "sha2",- "thiserror",- "uuid",- "zeroize",-]-[[package]]name = "log"version = "0.4.29"@@ -1626,7 +1626,7 @@ dependencies = [name = "sync"version = "0.1.0"dependencies = [- "llmchat-sync",+ "ensu-sync","serde","thiserror","uniffi",diff --git a/rust/uniffi/ensu/sync/Cargo.toml b/rust/uniffi/ensu/sync/Cargo.tomlindex 74783cfead..48555ed4fd 100644--- a/rust/uniffi/ensu/sync/Cargo.toml+++ b/rust/uniffi/ensu/sync/Cargo.toml@@ -8,7 +8,7 @@ name = "sync"crate-type = ["staticlib", "cdylib"][dependencies]-llmchat-sync = { path = "../../../ensu/sync" }+ensu-sync = { path = "../../../ensu/sync" }serde = { version = "1", features = ["derive"] }thiserror = "2"uniffi = { version = "0.31.0" }diff --git a/rust/uniffi/ensu/sync/src/api.rs b/rust/uniffi/ensu/sync/src/api.rsindex bb15899740..6a9c64775b 100644--- a/rust/uniffi/ensu/sync/src/api.rs+++ b/rust/uniffi/ensu/sync/src/api.rs@@ -1,4 +1,4 @@-use llmchat_sync as core;+use ensu_sync as core;use thiserror::Error;#[derive(Debug, Error, uniffi::Error)]@@ -174,12 +174,12 @@ pub fn fetch_chat_key(auth: SyncAuth, sync_db_path: String) -> Result<Vec<u8>, S}#[derive(uniffi::Object)]-pub struct LlmChatSync {+pub struct EnsuSync {inner: core::SyncEngine,}#[uniffi::export]-impl LlmChatSync {+impl EnsuSync {#[uniffi::constructor]pub fn open(main_db_path: String,diff --git a/rust/uniffi/ensu/sync/src/api.udl b/rust/uniffi/ensu/sync/src/api.udlindex c4071b6ade..bf7f2b4068 100644--- a/rust/uniffi/ensu/sync/src/api.udl+++ b/rust/uniffi/ensu/sync/src/api.udl@@ -25,9 +25,9 @@ dictionary SyncResult {};namespace sync {- interface LlmChatSync {+ interface EnsuSync {[Constructor, Throws=SyncError]- LlmChatSync(string main_db_path, string attachments_db_path, sequence<u8> db_key, string attachments_dir, string meta_dir, string? plaintext_dir);+ EnsuSync(string main_db_path, string attachments_db_path, sequence<u8> db_key, string attachments_dir, string meta_dir, string? plaintext_dir);[Throws=SyncError]SyncResult sync(SyncAuth auth);diff --git a/rust/uniffi/ensu/sync/uniffi.toml b/rust/uniffi/ensu/sync/uniffi.tomlindex a44873c5ea..dceee8d322 100644--- a/rust/uniffi/ensu/sync/uniffi.toml+++ b/rust/uniffi/ensu/sync/uniffi.toml@@ -2,7 +2,7 @@link_frameworks = ["Foundation"][bindings.kotlin]-package_name = "io.ente.labs.llmchat_sync"+package_name = "io.ente.labs.ensu_sync"cdylib_name = "sync"android = truekotlin_target_version = "1.9.0"