YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
handle device_name column
cparish3123f1201f2e4ff
diff --git a/screenpipe-server/benches/db_benchmarks.rs b/screenpipe-server/benches/db_benchmarks.rsindex e22ba8322..996e087d3 100644--- a/screenpipe-server/benches/db_benchmarks.rs+++ b/screenpipe-server/benches/db_benchmarks.rs@@ -13,7 +13,7 @@ async fn setup_large_db(size: usize) -> DatabaseManager {let mut rng = rand::thread_rng();for _ in 0..size {- let _video_id = db.insert_video_chunk("test_video.mp4").await.unwrap();+ let _video_id = db.insert_video_chunk("test_video.mp4", "test_device").await.unwrap();let frame_id = db.insert_frame().await.unwrap();let ocr_text = format!("OCR text {}", rng.gen::<u32>());let text_json = format!(r#"{{"text": "{}"}}"#, ocr_text);diff --git a/screenpipe-server/src/core.rs b/screenpipe-server/src/core.rsindex fa0775792..e6f347c9a 100644--- a/screenpipe-server/src/core.rs+++ b/screenpipe-server/src/core.rs@@ -190,15 +190,22 @@ async fn record_video(debug!("record_video: Starting");let db_chunk_callback = Arc::clone(&db);let rt = Handle::current();- let new_chunk_callback = move |file_path: &str| {+ let device_name = Arc::new(format!("monitor_{}", monitor_id));++ let new_chunk_callback = {let db_chunk_callback = Arc::clone(&db_chunk_callback);- let file_path = file_path.to_string();- rt.spawn(async move {- if let Err(e) = db_chunk_callback.insert_video_chunk(&file_path).await {- error!("Failed to insert new video chunk: {}", e);- }- debug!("record_video: Inserted new video chunk: {}", file_path);- });+ let device_name = Arc::clone(&device_name);+ move |file_path: &str| {+ let file_path = file_path.to_string();+ let db_chunk_callback = Arc::clone(&db_chunk_callback);+ let device_name = Arc::clone(&device_name);+ rt.spawn(async move {+ if let Err(e) = db_chunk_callback.insert_video_chunk(&file_path, &device_name).await {+ error!("Failed to insert new video chunk: {}", e);+ }+ debug!("record_video: Inserted new video chunk: {}", file_path);+ });+ }};let video_capture = VideoCapture::new(@@ -217,7 +224,7 @@ async fn record_video(while is_running.load(Ordering::SeqCst) {if let Some(frame) = video_capture.ocr_frame_queue.pop() {for window_result in &frame.window_ocr_results {- match db.insert_frame().await {+ match db.insert_frame(&device_name).await {Ok(frame_id) => {let text_json =serde_json::to_string(&window_result.text_json).unwrap_or_default();diff --git a/screenpipe-server/src/db.rs b/screenpipe-server/src/db.rsindex 3263341c6..0ac8ceac5 100644--- a/screenpipe-server/src/db.rs+++ b/screenpipe-server/src/db.rs@@ -260,10 +260,11 @@ impl DatabaseManager {Ok(affected as i64)}- pub async fn insert_video_chunk(&self, file_path: &str) -> Result<i64, sqlx::Error> {+ pub async fn insert_video_chunk(&self, file_path: &str, device_name: &str) -> Result<i64, sqlx::Error> {let mut tx = self.pool.begin().await?;- let id = sqlx::query("INSERT INTO video_chunks (file_path) VALUES (?1)")+ let id = sqlx::query("INSERT INTO video_chunks (file_path, device_name) VALUES (?1, ?2)").bind(file_path)+ .bind(device_name).execute(&mut *tx).await?.last_insert_rowid();@@ -271,13 +272,14 @@ impl DatabaseManager {Ok(id)}- pub async fn insert_frame(&self) -> Result<i64, sqlx::Error> {+ pub async fn insert_frame(&self, device_name: &str) -> Result<i64, sqlx::Error> {let mut tx = self.pool.begin().await?;debug!("insert_frame Transaction started");// Get the most recent video_chunk_idlet video_chunk_id: Option<i64> =- sqlx::query_scalar("SELECT id FROM video_chunks ORDER BY id DESC LIMIT 1")+ sqlx::query_scalar("SELECT id FROM video_chunks WHERE device_name = ?1 ORDER BY id DESC LIMIT 1")+ .bind(device_name).fetch_optional(&mut *tx).await?;debug!("Fetched most recent video_chunk_id: {:?}", video_chunk_id);diff --git a/screenpipe-server/src/server.rs b/screenpipe-server/src/server.rsindex c1b442c20..65e85252c 100644--- a/screenpipe-server/src/server.rs+++ b/screenpipe-server/src/server.rs@@ -863,6 +863,46 @@ async fn execute_raw_sql(}}+// #[derive(Deserialize)]+// #[serde(tag = "type", content = "data")]+// pub enum AddContentRequest {+// Frame(FrameContent),+// Transcription(AudioTranscription),+// }++// #[derive(Deserialize)]+// pub struct FrameContent {+// pub frame_id: i64,+// pub file_path: String,+// pub timestamp: Option<DateTime<Utc>>,+// pub app_name: Option<String>,+// pub window_name: Option<String>,+// pub ocr_results: Option<Vec<OCRContent>>,+// pub tags: Option<Vec<String>>, =+// }++// #[derive(Deserialize)]+// pub struct AudioTranscription {+// pub transcription: String,+// pub timestamp: Option<DateTime<Utc>>,+// pub file_path: String,+// pub tags: Option<Vec<String>>,+// pub device_name: Option<String>,+// }++// #[derive(Serialize)]+// pub struct AddContentResponse {+// pub success: bool,+// pub message: Option<String>,+// }++// pub(crate) async fn add_to_database(+// State(state): State<Arc<AppState>>,+// Json(payload): Json<AddContentRequest>,+// ) -> Result<JsonResponse<AddContentResponse>, (StatusCode, JsonResponse<Value>)> {++// }+#[cfg(feature = "experimental")]async fn input_control_handler(JsonResponse(payload): JsonResponse<InputControlRequest>,@@ -967,6 +1007,7 @@ pub fn create_router() -> Router<Arc<AppState>> {.route("/experimental/frames/merge", post(merge_frames_handler)).route("/health", get(health_check)).route("/raw_sql", post(execute_raw_sql));+ // .route("/add", post(add_to_database));#[cfg(feature = "llm")]let router = router.route("/llm/chat", post(llm_chat_handler));diff --git a/screenpipe-server/tests/db.rs b/screenpipe-server/tests/db.rsindex 3066f3a13..0f925b3e6 100644--- a/screenpipe-server/tests/db.rs+++ b/screenpipe-server/tests/db.rs@@ -14,8 +14,8 @@ mod tests {#[tokio::test]async fn test_insert_and_search_ocr() {let db = setup_test_db().await;- let _ = db.insert_video_chunk("test_video.mp4").await.unwrap();- let frame_id = db.insert_frame().await.unwrap();+ let _ = db.insert_video_chunk("test_video.mp4", "test_device").await.unwrap();+ let frame_id = db.insert_frame("test_device").await.unwrap();db.insert_ocr_text(frame_id,"Hello, world!",@@ -140,8 +140,8 @@ mod tests {let db = setup_test_db().await;// Insert OCR data- let _ = db.insert_video_chunk("test_video.mp4").await.unwrap();- let frame_id = db.insert_frame().await.unwrap();+ let _ = db.insert_video_chunk("test_video.mp4", "test_device").await.unwrap();+ let frame_id = db.insert_frame("test_device").await.unwrap();db.insert_ocr_text(frame_id,"Hello from OCR",@@ -203,8 +203,8 @@ mod tests {let start_time = Utc::now();// Insert OCR data- let _ = db.insert_video_chunk("test_video.mp4").await.unwrap();- let frame_id1 = db.insert_frame().await.unwrap();+ let _ = db.insert_video_chunk("test_video.mp4", "test_device").await.unwrap();+ let frame_id1 = db.insert_frame("test_device").await.unwrap();db.insert_ocr_text(frame_id1,"Hello from OCR 1",@@ -238,7 +238,7 @@ mod tests {tokio::time::sleep(tokio::time::Duration::from_millis(10)).await;// Insert remaining data- let frame_id2 = db.insert_frame().await.unwrap();+ let frame_id2 = db.insert_frame("test_device").await.unwrap();db.insert_ocr_text(frame_id2,"Hello from OCR 2",@@ -355,8 +355,8 @@ mod tests {let start_time = Utc::now();// Insert OCR data- let _ = db.insert_video_chunk("test_video.mp4").await.unwrap();- let frame_id1 = db.insert_frame().await.unwrap();+ let _ = db.insert_video_chunk("test_video.mp4", "test_device").await.unwrap();+ let frame_id1 = db.insert_frame("test_device").await.unwrap();db.insert_ocr_text(frame_id1,"Hello from OCR 1",@@ -388,7 +388,7 @@ mod tests {tokio::time::sleep(tokio::time::Duration::from_millis(10)).await;// Insert remaining data- let frame_id2 = db.insert_frame().await.unwrap();+ let frame_id2 = db.insert_frame("test_device").await.unwrap();db.insert_ocr_text(frame_id2,"Hello from OCR 2",diff --git a/screenpipe-server/tests/endpoint_test.rs b/screenpipe-server/tests/endpoint_test.rsindex 24c75086c..4fa32cb5d 100644--- a/screenpipe-server/tests/endpoint_test.rs+++ b/screenpipe-server/tests/endpoint_test.rs@@ -119,8 +119,8 @@ mod tests {tokio::time::sleep(tokio::time::Duration::from_secs(120)).await;// Insert some recent data- let _ = db.insert_video_chunk("test_video.mp4").await.unwrap();- let frame_id = db.insert_frame().await.unwrap();+ let _ = db.insert_video_chunk("test_video.mp4", "test_device").await.unwrap();+ let frame_id = db.insert_frame("test_device").await.unwrap();let _ = db.insert_ocr_text(frame_id,@@ -179,8 +179,8 @@ mod tests {// Insert some stale data (more than 60 seconds old)let stale_time = Utc::now() - Duration::seconds(61);- let _ = db.insert_video_chunk("test_video.mp4").await.unwrap();- let frame_id = db.insert_frame().await.unwrap();+ let _ = db.insert_video_chunk("test_video.mp4", "test_device").await.unwrap();+ let frame_id = db.insert_frame("test_device").await.unwrap();let _ = db.insert_ocr_text(frame_id,@@ -351,9 +351,9 @@ mod tests {let db = &state.db;// Insert some test data- let _ = db.insert_video_chunk("test_video1.mp4").await.unwrap();- let frame_id1 = db.insert_frame().await.unwrap();- let frame_id2 = db.insert_frame().await.unwrap();+ let _ = db.insert_video_chunk("test_video1.mp4", "test_device").await.unwrap();+ let frame_id1 = db.insert_frame("test_device").await.unwrap();+ let frame_id2 = db.insert_frame("test_device").await.unwrap();let _ = db.insert_ocr_text(frame_id1,@@ -503,8 +503,8 @@ mod tests {let db = &state.db;// insert test data with different timestamps- let _ = db.insert_video_chunk("test_video1.mp4").await.unwrap();- let frame_id1 = db.insert_frame().await.unwrap();+ let _ = db.insert_video_chunk("test_video1.mp4", "test_device").await.unwrap();+ let frame_id1 = db.insert_frame("test_device").await.unwrap();let audio_chunk_id1 = db.insert_audio_chunk("test_audio1.wav").await.unwrap();let now = DateTime::parse_from_rfc3339("2024-09-21T10:49:23.240367Z")diff --git a/screenpipe-server/tests/tags_test.rs b/screenpipe-server/tests/tags_test.rsindex 9bef78ae4..bb1761286 100644--- a/screenpipe-server/tests/tags_test.rs+++ b/screenpipe-server/tests/tags_test.rs@@ -357,10 +357,10 @@ async fn test_search_by_multiple_tags() {async fn insert_test_data(db: &Arc<DatabaseManager>) {// Insert test video chunk- let _video_chunk_id = db.insert_video_chunk("test_video_file.mp4").await.unwrap();+ let _video_chunk_id = db.insert_video_chunk("test_video_file.mp4", "test_device").await.unwrap();// Insert test frame- let frame_id = db.insert_frame().await.unwrap();+ let frame_id = db.insert_frame("test_device").await.unwrap();// Insert test OCR datadb.insert_ocr_text(