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
feat
Louis Beaumont4d3226fdbc5e
diff --git a/screenpipe-server/src/db.rs b/screenpipe-server/src/db.rsindex 2943c1592..6afbc27f2 100644--- a/screenpipe-server/src/db.rs+++ b/screenpipe-server/src/db.rs@@ -506,6 +506,8 @@ impl DatabaseManager {end_time: Option<DateTime<Utc>>,app_name: Option<&str>,window_name: Option<&str>,+ min_length: Option<usize>,+ max_length: Option<usize>,) -> Result<Vec<SearchResult>, sqlx::Error> {let mut results = Vec::new();@@ -520,20 +522,27 @@ impl DatabaseManager {end_time,app_name,window_name,- ) // Add window_name parameter+ min_length,+ max_length,+ ).await?;results.extend(ocr_results.into_iter().map(SearchResult::OCR));} else {if content_type == ContentType::All || content_type == ContentType::OCR {let ocr_results = self- .search_ocr(query, limit, offset, start_time, end_time, None, None)+ .search_ocr(+ query, limit, offset, start_time, end_time, None, None, min_length,+ max_length,+ ).await?;results.extend(ocr_results.into_iter().map(SearchResult::OCR));}if content_type == ContentType::All || content_type == ContentType::Audio {let audio_results = self- .search_audio(query, limit, offset, start_time, end_time)+ .search_audio(+ query, limit, offset, start_time, end_time, min_length, max_length,+ ).await?;results.extend(audio_results.into_iter().map(SearchResult::Audio));}@@ -628,6 +637,8 @@ impl DatabaseManager {end_time: Option<DateTime<Utc>>,app_name: Option<&str>,window_name: Option<&str>,+ min_length: Option<usize>,+ max_length: Option<usize>,) -> Result<Vec<OCRResult>, sqlx::Error> {let mut sql = r#"SELECT@@ -677,6 +688,16 @@ impl DatabaseManager {));}+ if let Some(_) = min_length {+ param_count += 1;+ sql.push_str(&format!(" AND LENGTH(ocr_text.text) >= ?{}", param_count));+ }++ if let Some(_) = max_length {+ param_count += 1;+ sql.push_str(&format!(" AND LENGTH(ocr_text.text) <= ?{}", param_count));+ }+sql.push_str(r#"GROUP BY@@ -702,6 +723,14 @@ impl DatabaseManager {query = query.bind(window_name);}+ if let Some(min) = min_length {+ query = query.bind(min as i64);+ }++ if let Some(max) = max_length {+ query = query.bind(max as i64);+ }+let ocr_results_raw = query.fetch_all(&self.pool).await?;let ocr_results = ocr_results_raw@@ -733,8 +762,10 @@ impl DatabaseManager {offset: u32,start_time: Option<DateTime<Utc>>,end_time: Option<DateTime<Utc>>,+ min_length: Option<usize>,+ max_length: Option<usize>,) -> Result<Vec<AudioResult>, sqlx::Error> {- let sql = r#"+ let mut sql = r#"SELECTaudio_transcriptions.audio_chunk_id,audio_transcriptions.transcription,@@ -755,24 +786,56 @@ impl DatabaseManager {audio_transcriptions.transcription LIKE '%' || ?1 || '%' COLLATE NOCASEAND (?2 IS NULL OR audio_transcriptions.timestamp >= ?2)AND (?3 IS NULL OR audio_transcriptions.timestamp <= ?3)- GROUP BY- audio_transcriptions.audio_chunk_id,- audio_transcriptions.transcription,- audio_transcriptions.timestamp,- audio_transcriptions.offset_index- ORDER BY- audio_transcriptions.timestamp DESC- LIMIT ?4 OFFSET ?5- "#;+ "#+ .to_string();++ let mut param_count = 4; // We already have 4 parameters++ if let Some(_) = min_length {+ param_count += 1;+ sql.push_str(&format!(+ " AND LENGTH(audio_transcriptions.transcription) >= ?{}",+ param_count+ ));+ }++ if let Some(_) = max_length {+ param_count += 1;+ sql.push_str(&format!(+ " AND LENGTH(audio_transcriptions.transcription) <= ?{}",+ param_count+ ));+ }- let audio_results_raw = sqlx::query_as::<_, AudioResultRaw>(sql)+ sql.push_str(+ r#"+ GROUP BY+ audio_transcriptions.audio_chunk_id,+ audio_transcriptions.transcription,+ audio_transcriptions.timestamp,+ audio_transcriptions.offset_index+ ORDER BY+ audio_transcriptions.timestamp DESC+ LIMIT ?4 OFFSET ?5+ "#,+ );++ let mut query = sqlx::query_as::<_, AudioResultRaw>(&sql).bind(query).bind(start_time).bind(end_time).bind(limit)- .bind(offset)- .fetch_all(&self.pool)- .await?;+ .bind(offset);++ if let Some(min) = min_length {+ query = query.bind(min as i64);+ }++ if let Some(max) = max_length {+ query = query.bind(max as i64);+ }++ let audio_results_raw = query.fetch_all(&self.pool).await?;// Parse the tags string into a Vec<String>let audio_results = audio_results_raw@@ -820,28 +883,40 @@ impl DatabaseManager {start_time: Option<DateTime<Utc>>,end_time: Option<DateTime<Utc>>,app_name: Option<&str>,- window_name: Option<&str>, // Add window_name parameter+ window_name: Option<&str>,+ min_length: Option<usize>,+ max_length: Option<usize>,) -> Result<usize, sqlx::Error> {let mut total_count = 0;// If app_name is specified, only count OCR resultsif app_name.is_some() || window_name.is_some() {let ocr_count = self- .count_ocr_results(query, start_time, end_time, app_name, window_name) // Add window_name parameter+ .count_ocr_results(+ query,+ start_time,+ end_time,+ app_name,+ window_name,+ min_length,+ max_length,+ ).await?;total_count += ocr_count;} else {// If no app_name is specified, proceed with normal countingif content_type == ContentType::All || content_type == ContentType::OCR {let ocr_count = self- .count_ocr_results(query, start_time, end_time, None, None) // Add window_name parameter+ .count_ocr_results(+ query, start_time, end_time, None, None, min_length, max_length,+ ).await?;total_count += ocr_count;}if content_type == ContentType::All || content_type == ContentType::Audio {let audio_count = self- .count_audio_results(query, start_time, end_time)+ .count_audio_results(query, start_time, end_time, min_length, max_length).await?;total_count += audio_count;}@@ -897,7 +972,9 @@ impl DatabaseManager {start_time: Option<DateTime<Utc>>,end_time: Option<DateTime<Utc>>,app_name: Option<&str>,- window_name: Option<&str>, // Add window_name parameter+ window_name: Option<&str>,+ min_length: Option<usize>,+ max_length: Option<usize>,) -> Result<usize, sqlx::Error> {let mut sql = r#"SELECT COUNT(*)@@ -917,6 +994,14 @@ impl DatabaseManager {sql.push_str(" AND ocr_text.window_name = ?7 COLLATE NOCASE");}+ if min_length.is_some() {+ sql.push_str(" AND LENGTH(ocr_text.text) >= ?4");+ }++ if max_length.is_some() {+ sql.push_str(" AND LENGTH(ocr_text.text) <= ?5");+ }+let mut query = sqlx::query_as::<_, (i64,)>(&sql).bind(query).bind(start_time)@@ -930,6 +1015,14 @@ impl DatabaseManager {query = query.bind(window_name);}+ if let Some(min) = min_length {+ query = query.bind(min as i64);+ }++ if let Some(max) = max_length {+ query = query.bind(max as i64);+ }+let (count,) = query.fetch_one(&self.pool).await?;Ok(count as usize)}@@ -938,6 +1031,8 @@ impl DatabaseManager {query: &str,start_time: Option<DateTime<Utc>>,end_time: Option<DateTime<Utc>>,+ min_length: Option<usize>,+ max_length: Option<usize>,) -> Result<usize, sqlx::Error> {let (count,): (i64,) = sqlx::query_as(r#"@@ -946,11 +1041,15 @@ impl DatabaseManager {WHERE transcription LIKE '%' || ?1 || '%' COLLATE NOCASEAND (?2 IS NULL OR timestamp >= ?2)AND (?3 IS NULL OR timestamp <= ?3)- "#,+ AND (?4 IS NULL OR LENGTH(transcription) >= ?4)+ AND (?5 IS NULL OR LENGTH(transcription) <= ?5)+ "#,).bind(query).bind(start_time).bind(end_time)+ .bind(min_length.map(|len| len as i64))+ .bind(max_length.map(|len| len as i64)).fetch_one(&self.pool).await?;diff --git a/screenpipe-server/src/server.rs b/screenpipe-server/src/server.rsindex 191129ea2..ecb60f08b 100644--- a/screenpipe-server/src/server.rs+++ b/screenpipe-server/src/server.rs@@ -58,11 +58,15 @@ pub(crate) struct SearchQuery {#[serde(default)]end_time: Option<DateTime<Utc>>,#[serde(default)]- app_name: Option<String>, // Add this line+ app_name: Option<String>,#[serde(default)]- window_name: Option<String>, // Add this line+ window_name: Option<String>,#[serde(default)]include_frames: bool,+ #[serde(default)]+ min_length: Option<usize>,+ #[serde(default)]+ max_length: Option<usize>,}#[derive(Deserialize)]@@ -135,7 +139,7 @@ pub struct FTSContent {pub frame_id: i64,pub timestamp: DateTime<Utc>,pub app_name: String,- pub window_name: String, // Add this field+ pub window_name: String,pub file_path: String,pub original_frame_text: Option<String>,pub tags: Vec<String>,@@ -192,6 +196,7 @@ pub struct HealthCheckResponse {pub verbose_instructions: Option<String>,}+// Update the search functionpub(crate) async fn search(Query(query): Query<SearchQuery>,State(state): State<Arc<AppState>>,@@ -200,7 +205,7 @@ pub(crate) async fn search((StatusCode, JsonResponse<serde_json::Value>),> {info!(- "Received search request: query='{}', content_type={:?}, limit={}, offset={}, start_time={:?}, end_time={:?}, app_name={:?}, window_name={:?}",+ "Received search request: query='{}', content_type={:?}, limit={}, offset={}, start_time={:?}, end_time={:?}, app_name={:?}, window_name={:?}, min_length={:?}, max_length={:?}",query.q.as_deref().unwrap_or(""),query.content_type,query.pagination.limit,@@ -208,7 +213,9 @@ pub(crate) async fn search(query.start_time,query.end_time,query.app_name,- query.window_name // Log window_name+ query.window_name,+ query.min_length,+ query.max_length);let query_str = query.q.as_deref().unwrap_or("");@@ -231,6 +238,8 @@ pub(crate) async fn search(query.end_time,query.app_name.as_deref(),query.window_name.as_deref(),+ query.min_length,+ query.max_length,).await{@@ -252,7 +261,9 @@ pub(crate) async fn search(query.start_time,query.end_time,query.app_name.as_deref(),- query.window_name.as_deref(), // Add window_name parameter+ query.window_name.as_deref(),+ query.min_length,+ query.max_length,).await.map_err(|e| {@@ -907,4 +918,29 @@ curl -X POST "http://localhost:3030/pipes/update" \}}' | jq++# Basic search with min_length and max_length+curl "http://localhost:3030/search?q=test&limit=10&offset=0&min_length=5&max_length=50" | jq++# Search for OCR content with length constraints+curl "http://localhost:3030/search?q=code&content_type=ocr&limit=5&offset=0&min_length=20&max_length=100" | jq++# Search for audio content with length constraints+curl "http://localhost:3030/search?q=meeting&content_type=audio&limit=5&offset=0&min_length=50&max_length=200" | jq++# Search with time range and length constraints+curl "http://localhost:3030/search?q=project&limit=10&offset=0&min_length=10&max_length=100&start_time=$(date -u -v-1H +%Y-%m-%dT%H:%M:%SZ)&end_time=$(date -u +%Y-%m-%dT%H:%M:%SZ)" | jq++# Search with app_name and length constraints+curl "http://localhost:3030/search?app_name=vscode&limit=5&offset=0&min_length=15&max_length=150" | jq++# Search with window_name and length constraints+curl "http://localhost:3030/search?window_name=alacritty&limit=5&offset=0&min_length=5&max_length=50" | jq++# Search for very short content+curl "http://localhost:3030/search?q=&limit=10&offset=0&max_length=10" | jq++# Search for very long content+curl "http://localhost:3030/search?q=&limit=10&offset=0&min_length=500" | jq+*/