A local-first private AI assistant for everyday use. Runs on-device models with encrypted P2P sync, and supports sharing chats publicly on ATProto.
10
fork

Configure Feed

Select the types of activity you want to include in your feed.

wip

madclaws efa3ba67 120d1b2e

+32 -14
+6 -5
tiles/src/core/accounts.rs
··· 12 12 use uuid::Uuid; 13 13 14 14 use crate::{ 15 - core::storage::db::{DBTYPE, get_db_conn}, 15 + core::storage::db::{DBTYPE, Dbconn, get_db_conn}, 16 16 utils::config::{get_or_create_config, save_config}, 17 17 }; 18 18 const ROOT_USER_CONFIG_KEY: &str = "root-user"; ··· 249 249 .map_err(<rusqlite::Error as Into<anyhow::Error>>::into) 250 250 } 251 251 252 - pub fn save_root_account_db() -> Result<()> { 253 - let conn = get_db_conn(DBTYPE::COMMON)?; 252 + pub fn save_root_account_db(db_conn: &Dbconn) -> Result<()> { 254 253 let config = get_or_create_config()?; 255 254 let root_user = get_root_user_details(&config)?; 256 255 let user = User { ··· 270 269 .as_secs(), 271 270 }; 272 271 273 - let mut fetch_root_user = conn.prepare("select id from users where root = true")?; 272 + let mut fetch_root_user = db_conn 273 + .common 274 + .prepare("select id from users where root = true")?; 274 275 275 276 match fetch_root_user.query_one([], |_row| Ok(())) { 276 277 Err(rusqlite::Error::QueryReturnedNoRows) => { 277 - conn.execute("insert into users (id, user_id, username, active_profile, account_type, root) values 278 + db_conn.common.execute("insert into users (id, user_id, username, active_profile, account_type, root) values 278 279 (?1, ?2, ?3,?4, ?5, ?6)", (&user.id.to_string(), &user.user_id, &user.username, &user.active_profile, 279 280 user.account_type.to_string(), &user.root))?; 280 281 Ok(())
+6 -4
tiles/src/core/mod.rs
··· 5 5 6 6 use anyhow::Result; 7 7 8 - use crate::core::{accounts::save_root_account_db, storage::db::init_db}; 8 + use crate::core::{ 9 + accounts::save_root_account_db, 10 + storage::db::{Dbconn, init_db}, 11 + }; 9 12 10 13 pub mod accounts; 11 14 pub mod chats; ··· 14 17 pub mod storage; 15 18 16 19 // Entrypoint of the core 17 - pub fn init() -> Result<()> { 18 - init_db()?; 19 - save_root_account_db() 20 + pub fn init(db_conn: &Dbconn) -> Result<()> { 21 + save_root_account_db(db_conn) 20 22 }
+12 -2
tiles/src/core/storage/db.rs
··· 15 15 CHAT, 16 16 } 17 17 18 + pub struct Dbconn { 19 + pub chat: Connection, 20 + pub common: Connection, 21 + } 22 + 18 23 // DEFINE MIGRATIONS 19 24 20 25 // TODO: add the schema doc ··· 67 72 68 73 const CHATS_MIGRATIONS: Migrations = Migrations::from_slice(CHATS_MIGRATION_ARRAY); 69 74 70 - pub fn init_db() -> Result<()> { 75 + pub fn init_db() -> Result<Dbconn> { 71 76 let mut chat_conn = get_db_conn(DBTYPE::CHAT)?; 72 77 let mut common_conn = get_db_conn(DBTYPE::COMMON)?; 73 78 74 - apply_migrations(&mut common_conn, &mut chat_conn) 79 + apply_migrations(&mut common_conn, &mut chat_conn)?; 80 + 81 + Ok(Dbconn { 82 + chat: chat_conn, 83 + common: common_conn, 84 + }) 75 85 } 76 86 77 87 pub fn get_db_conn(db_type: DBTYPE) -> Result<Connection> {
+8 -3
tiles/src/main.rs
··· 5 5 use clap::{Args, Parser, Subcommand}; 6 6 use tiles::{ 7 7 core::{ 8 - self, 8 + self, init, 9 9 network::{link, sync}, 10 + storage::db::init_db, 10 11 }, 11 12 daemon::{start_cmd, start_server, stop_cmd}, 12 13 runtime::{RunArgs, build_runtime}, ··· 188 189 env_logger::try_init()?; 189 190 let cli = Cli::parse(); 190 191 let runtime = build_runtime(); 192 + let db_conn = init_db()?; 193 + 191 194 match cli.command { 192 195 None => { 193 196 // Running tiles without subcommand - launch default model with flags ··· 207 210 let _ = start_cmd(None).await; 208 211 }); 209 212 } 210 - core::init().inspect_err(|e| eprintln!("Tiles core init failed due to {:?}", e))?; 213 + core::init(&db_conn) 214 + .inspect_err(|e| eprintln!("Tiles core init failed due to {:?}", e))?; 211 215 if !cli.flags.no_repl { 212 216 commands::run(&runtime, run_args) 213 217 .await ··· 223 227 relay_count: flags.relay_count, 224 228 memory: flags.memory, 225 229 }; 226 - core::init().inspect_err(|e| eprintln!("Tiles core init failed due to {:?}", e))?; 230 + core::init(&db_conn) 231 + .inspect_err(|e| eprintln!("Tiles core init failed due to {:?}", e))?; 227 232 commands::run(&runtime, run_args) 228 233 .await 229 234 .inspect_err(|e| eprintln!("Tiles failed to run due to {:?}", e))?;