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
fix: audio device type auto-detection, rate limiter resilience, app version logging
Louis Beaumontd40ed6ff0100
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/main.rs b/apps/screenpipe-app-tauri/src-tauri/src/main.rsindex 4f5dc8050..d0dede4c9 100755--- a/apps/screenpipe-app-tauri/src-tauri/src/main.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/main.rs@@ -1066,6 +1066,7 @@ async fn main() {// Install Pi coding agent in background (fire-and-forget, never crashes)crate::pi::ensure_pi_installed_background();+ info!("App version: {}", env!("CARGO_PKG_VERSION"));info!("Local data directory: {}", base_dir.display());// PostHog analytics setupdiff --git a/crates/screenpipe-audio/src/core/device.rs b/crates/screenpipe-audio/src/core/device.rsindex 7334d0bbf..917c26309 100644--- a/crates/screenpipe-audio/src/core/device.rs+++ b/crates/screenpipe-audio/src/core/device.rs@@ -82,19 +82,38 @@ impl AudioDevice {return Err(anyhow!("Device name cannot be empty"));}- let (name, device_type) = match name.to_lowercase() {- n if n.ends_with("(input)") => (- name.trim_end_matches("(input)").trim().to_string(),+ let lower = name.to_lowercase();+ let (name, device_type) = match lower {+ ref n if n.ends_with("(input)") => (+ name[..name.len() - "(input)".len()].trim().to_string(),DeviceType::Input,),- n if n.ends_with("(output)") => (- name.trim_end_matches("(output)").trim().to_string(),+ ref n if n.ends_with("(output)") => (+ name[..name.len() - "(output)".len()].trim().to_string(),DeviceType::Output,),_ => {- return Err(anyhow!(- "Device type (input/output) not specified in the name"- ))+ // No suffix — probe the system to determine the actual type.+ // This handles bare device names from old configs, API calls,+ // or system-reported names without a type suffix.+ let bare = name.trim();+ let device_type = detect_device_type_from_system(bare);+ match device_type {+ Some(dt) => {+ tracing::info!(+ "audio device '{}' has no (input)/(output) suffix, detected as {:?} from system",+ bare, dt+ );+ (bare.to_string(), dt)+ }+ None => {+ return Err(anyhow!(+ "Device type (input/output) not specified in the name '{}' \+ and device was not found in system audio devices",+ bare+ ))+ }+ }}};@@ -120,6 +139,46 @@ pub fn parse_audio_device(name: &str) -> Result<AudioDevice> {AudioDevice::from_name(name)}+/// Probe the system's audio devices to determine whether `bare_name` is an+/// input or output device. Returns `None` if the device isn't found at all.+/// If found in both input and output lists, prefer Input (mics are more+/// commonly specified by bare name; output devices use canonical paths).+#[cfg(not(all(target_os = "linux", feature = "pulseaudio")))]+fn detect_device_type_from_system(bare_name: &str) -> Option<DeviceType> {+ use cpal::traits::{DeviceTrait, HostTrait};+ let host = cpal::default_host();++ let is_input = host+ .input_devices()+ .map(|mut devs| devs.any(|d| d.name().ok().as_deref() == Some(bare_name)))+ .unwrap_or(false);++ let is_output = host+ .output_devices()+ .map(|mut devs| devs.any(|d| d.name().ok().as_deref() == Some(bare_name)))+ .unwrap_or(false);++ match (is_input, is_output) {+ (true, _) => Some(DeviceType::Input), // prefer input if ambiguous+ (false, true) => Some(DeviceType::Output),+ (false, false) => None,+ }+}++#[cfg(all(target_os = "linux", feature = "pulseaudio"))]+fn detect_device_type_from_system(bare_name: &str) -> Option<DeviceType> {+ // PulseAudio devices are listed via a different path; try pulse sources+ // (input) then sinks (output). If neither matches, return None.+ if let Ok(devices) = super::pulse::list_pulse_devices() {+ for device in &devices {+ if device.name == bare_name {+ return Some(device.device_type.clone());+ }+ }+ }+ None+}+/// Attempts an operation with exponential backoff retry#[cfg(target_os = "macos")]async fn with_retry<T, F, Fut>(operation: F, max_retries: usize) -> Result<T>diff --git a/packages/ai-gateway/src/utils/rate-limiter.ts b/packages/ai-gateway/src/utils/rate-limiter.tsindex 349002215..b63799299 100644--- a/packages/ai-gateway/src/utils/rate-limiter.ts+++ b/packages/ai-gateway/src/utils/rate-limiter.ts@@ -93,14 +93,32 @@ export async function checkRateLimit(url.searchParams.set('tier', tier);url.searchParams.set('rpm', String(getTierConfig(env)[tier]?.rpm || 5));- const rateLimitResponse = await rateLimiter.fetch(url.toString());- const rateLimitData = (await rateLimitResponse.json()) as {+ let rateLimitResponse: Response;+ try {+ rateLimitResponse = await rateLimiter.fetch(url.toString());+ } catch (err: any) {+ console.error('rate limiter durable object error, failing open:', err?.message);+ return { allowed: true };+ }++ if (!rateLimitResponse.ok) {+ console.error('rate limiter returned status', rateLimitResponse.status);+ return { allowed: true };+ }++ let rateLimitData: {allowed: boolean;remaining: number;reset_in: number;tier: string;rpm_limit: number;};+ try {+ rateLimitData = await rateLimitResponse.json();+ } catch (err: any) {+ console.error('rate limiter response parse error, failing open:', err?.message);+ return { allowed: true };+ }if (!rateLimitData.allowed) {return {