Skip to content

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

chore: various fixes and improvements

Louis Beaumontd833bccdbf06
diff --git a/screenpipe-accessibility/src/platform/macos.rs b/screenpipe-accessibility/src/platform/macos.rs
index 8dd06d656..c84b7127e 100644
--- a/screenpipe-accessibility/src/platform/macos.rs
+++ b/screenpipe-accessibility/src/platform/macos.rs
@@ -786,9 +786,7 @@ fn get_element_at_position(x: f64, y: f64, config: &UiCaptureConfig) -> Option<E
let s = format!("{:?}", r);
if let Some(start) = s.find("AX") {
let rest = &s[start..];
- let end = rest
- .find([')', '"', '}'])
- .unwrap_or(rest.len());
+ let end = rest.find([')', '"', '}']).unwrap_or(rest.len());
rest[..end].to_string()
} else {
"Unknown".to_string()
diff --git a/screenpipe-app-tauri/components/settings/recording-settings.tsx b/screenpipe-app-tauri/components/settings/recording-settings.tsx
index 9d367df2a..5bc079add 100644
--- a/screenpipe-app-tauri/components/settings/recording-settings.tsx
+++ b/screenpipe-app-tauri/components/settings/recording-settings.tsx
@@ -43,8 +43,7 @@ import {
CommandGroup,
CommandItem,
} from "@/components/ui/command";
-import { Command as TauriCommand } from "@tauri-apps/plugin-shell";
-import { commands, SettingsStore } from "@/lib/utils/tauri";
+import { commands, SettingsStore, MonitorDevice, AudioDeviceInfo } from "@/lib/utils/tauri";
import {
useSettings,
@@ -91,18 +90,7 @@ type PermissionsStatus = {
microphone: string;
};
-interface AudioDevice {
- name: string;
- is_default: boolean;
-}
-
-interface MonitorDevice {
- id: string;
- name: string;
- is_default: boolean;
- width: number;
- height: number;
-}
+// AudioDeviceInfo and MonitorDevice are imported from @/lib/utils/tauri
const createWindowOptions = (
windowItems: { name: string }[],
@@ -175,7 +163,7 @@ export function RecordingSettings() {
[]
);
const [availableAudioDevices, setAvailableAudioDevices] = useState<
- AudioDevice[]
+ AudioDeviceInfo[]
>([]);
const { toast } = useToast();
const [isUpdating, setIsUpdating] = useState(false);
@@ -270,44 +258,21 @@ export function RecordingSettings() {
useEffect(() => {
const loadDevices = async () => {
try {
- // Use sidecar command to fetch monitors
- const monitorCommand = TauriCommand.sidecar("screenpipe", [
- "vision",
- "list",
- "-o",
- "json",
- ]);
-
- const monitorOutput = await monitorCommand.execute();
- if (monitorOutput.code !== 0) {
- throw new Error(`Failed to fetch monitors: ${monitorOutput.stderr}`);
+ // Fetch monitors using Tauri command
+ const monitorResult = await commands.getMonitors();
+ if (monitorResult.status === "error") {
+ throw new Error(`Failed to fetch monitors: ${monitorResult.error}`);
}
-
- // Parse the JSON response which might be in {data: [...], success: true} format
- const monitorResponse = JSON.parse(monitorOutput.stdout);
- const monitors: MonitorDevice[] =
- monitorResponse.data || monitorResponse;
+ const monitors = monitorResult.data;
console.log("monitors", monitors);
setAvailableMonitors(monitors);
- // Use sidecar command to fetch audio devices
- const audioCommand = TauriCommand.sidecar("screenpipe", [
- "audio",
- "list",
- "-o",
- "json",
- ]);
-
- const audioOutput = await audioCommand.execute();
- if (audioOutput.code !== 0) {
- throw new Error(
- `Failed to fetch audio devices: ${audioOutput.stderr}`
- );
+ // Fetch audio devices using Tauri command
+ const audioResult = await commands.getAudioDevices();
+ if (audioResult.status === "error") {
+ throw new Error(`Failed to fetch audio devices: ${audioResult.error}`);
}
-
- // Parse the JSON response which might be in {data: [...], success: true} format
- const audioResponse = JSON.parse(audioOutput.stdout);
- const audioDevices: AudioDevice[] = audioResponse.data || audioResponse;
+ const audioDevices = audioResult.data;
console.log("audioDevices", audioDevices);
setAvailableAudioDevices(audioDevices);
@@ -324,7 +289,7 @@ export function RecordingSettings() {
if (updatedMonitorIds.length === 0) {
updatedMonitorIds = [
- monitors.find((monitor) => monitor.is_default)!.id!.toString(),
+ monitors.find((monitor) => monitor.isDefault)!.id!.toString(),
]
}
@@ -343,7 +308,7 @@ export function RecordingSettings() {
audioDevices.length > 0)
) {
updatedAudioDevices = audioDevices
- .filter((device) => device.is_default)
+ .filter((device) => device.isDefault)
.map((device) => device.name);
}
@@ -1171,7 +1136,7 @@ export function RecordingSettings() {
)}
/>
{device.name}
- {device.is_default && (
+ {device.isDefault && (
<Badge variant="secondary" className="ml-2">
Default
</Badge>
@@ -1463,7 +1428,7 @@ export function RecordingSettings() {
<p className="font-medium">{monitor.name}</p>
<p className="text-sm text-muted-foreground">
{monitor.width}x{monitor.height}
- {monitor.is_default && " (Default)"}
+ {monitor.isDefault && " (Default)"}
</p>
</div>
<Check
diff --git a/screenpipe-app-tauri/lib/utils/tauri.ts b/screenpipe-app-tauri/lib/utils/tauri.ts
index 2150b50a4..baa583736 100644
--- a/screenpipe-app-tauri/lib/utils/tauri.ts
+++ b/screenpipe-app-tauri/lib/utils/tauri.ts
@@ -79,6 +79,22 @@ async stopScreenpipe() : Promise<Result<null, string>> {
else return { status: "error", error: e as any };
}
},
+async getMonitors() : Promise<Result<MonitorDevice[], string>> {
+ try {
+ return { status: "ok", data: await TAURI_INVOKE("get_monitors") };
+} catch (e) {
+ if(e instanceof Error) throw e;
+ else return { status: "error", error: e as any };
+}
+},
+async getAudioDevices() : Promise<Result<AudioDeviceInfo[], string>> {
+ try {
+ return { status: "ok", data: await TAURI_INVOKE("get_audio_devices") };
+} catch (e) {
+ if(e instanceof Error) throw e;
+ else return { status: "error", error: e as any };
+}
+},
async getDiskUsage(forceRefresh: boolean | null) : Promise<Result<JsonValue, string>> {
try {
return { status: "ok", data: await TAURI_INVOKE("get_disk_usage", { forceRefresh }) };
@@ -481,10 +497,12 @@ async obsidianCancelSync() : Promise<Result<null, string>> {
export type AIPreset = { id: string; prompt: string; provider: AIProviderType; url?: string; model?: string; defaultPreset: boolean; apiKey: string | null; maxContextChars: number }
export type AIProviderType = "openai" | "native-ollama" | "custom" | "screenpipe-cloud" | "opencode"
+export type AudioDeviceInfo = { name: string; isDefault: boolean }
export type Credits = { amount: number }
export type EmbeddedLLM = { enabled: boolean; model: string; port: number }
export type JsonValue = null | boolean | number | string | JsonValue[] | { [key in string]: JsonValue }
export type LogFile = { name: string; path: string; modified_at: bigint }
+export type MonitorDevice = { id: number; name: string; isDefault: boolean; width: number; height: number }
export type OSPermission = "screenRecording" | "microphone" | "accessibility"
export type OSPermissionStatus = "notNeeded" | "empty" | "granted" | "denied"
export type OSPermissionsCheck = { screenRecording: OSPermissionStatus; microphone: OSPermissionStatus; accessibility: OSPermissionStatus }
diff --git a/screenpipe-app-tauri/src-tauri/src/commands.rs b/screenpipe-app-tauri/src-tauri/src/commands.rs
index 66318903c..a5d946093 100644
--- a/screenpipe-app-tauri/src-tauri/src/commands.rs
+++ b/screenpipe-app-tauri/src-tauri/src/commands.rs
@@ -1,4 +1,4 @@
-use crate::{get_data_dir, window_api::ShowRewindWindow, store::OnboardingStore, store::SettingsStore, parse_shortcut};
+use crate::{window_api::ShowRewindWindow, store::OnboardingStore, store::SettingsStore, parse_shortcut};
use tauri::{Manager, Emitter};
use tracing::{error, info};
diff --git a/screenpipe-app-tauri/src-tauri/src/main.rs b/screenpipe-app-tauri/src-tauri/src/main.rs
index 7daeb4855..74549b998 100755
--- a/screenpipe-app-tauri/src-tauri/src/main.rs
+++ b/screenpipe-app-tauri/src-tauri/src/main.rs
@@ -783,6 +783,8 @@ async fn main() {
update_global_shortcuts,
spawn_screenpipe,
stop_screenpipe,
+ sidecar::get_monitors,
+ sidecar::get_audio_devices,
// Commands from commands.rs
commands::get_disk_usage,
commands::open_pipe_window,
@@ -907,6 +909,8 @@ async fn main() {
.invoke_handler(tauri::generate_handler![
spawn_screenpipe,
stop_screenpipe,
+ sidecar::get_monitors,
+ sidecar::get_audio_devices,
permissions::open_permission_settings,
permissions::request_permission,
permissions::do_permissions_check,
diff --git a/screenpipe-app-tauri/src-tauri/src/server.rs b/screenpipe-app-tauri/src-tauri/src/server.rs
index c95cb1917..af0514db2 100644
--- a/screenpipe-app-tauri/src-tauri/src/server.rs
+++ b/screenpipe-app-tauri/src-tauri/src/server.rs
@@ -377,7 +377,7 @@ async fn set_window_size(
async fn start_sidecar(
State(state): State<ServerState>,
) -> Result<Json<ApiResponse>, (StatusCode, String)> {
- info!("received request to start sidecar");
+ info!("received request to start screenpipe server");
let app_handle = state.app_handle.clone();
match crate::sidecar::spawn_screenpipe(
@@ -389,13 +389,13 @@ async fn start_sidecar(
{
Ok(_) => Ok(Json(ApiResponse {
success: true,
- message: "sidecar started successfully".to_string(),
+ message: "screenpipe server started successfully".to_string(),
})),
Err(e) => {
- error!("failed to start sidecar: {}", e);
+ error!("failed to start screenpipe server: {}", e);
Err((
StatusCode::INTERNAL_SERVER_ERROR,
- format!("failed to start sidecar: {}", e),
+ format!("failed to start screenpipe server: {}", e),
))
}
}
@@ -404,7 +404,7 @@ async fn start_sidecar(
async fn stop_sidecar(
State(state): State<ServerState>,
) -> Result<Json<ApiResponse>, (StatusCode, String)> {
- info!("received request to stop sidecar");
+ info!("received request to stop screenpipe server");
let app_handle = state.app_handle.clone();
match crate::sidecar::stop_screenpipe(
@@ -415,13 +415,13 @@ async fn stop_sidecar(
{
Ok(_) => Ok(Json(ApiResponse {
success: true,
- message: "sidecar stopped successfully".to_string(),
+ message: "screenpipe server stopped successfully".to_string(),
})),
Err(e) => {
- error!("failed to stop sidecar: {}", e);
+ error!("failed to stop screenpipe server: {}", e);
Err((
StatusCode::INTERNAL_SERVER_ERROR,
- format!("failed to stop sidecar: {}", e),
+ format!("failed to stop screenpipe server: {}", e),
))
}
}
diff --git a/screenpipe-app-tauri/src-tauri/src/sidecar.rs b/screenpipe-app-tauri/src-tauri/src/sidecar.rs
index e8d3b1308..aa4b6994e 100644
--- a/screenpipe-app-tauri/src-tauri/src/sidecar.rs
+++ b/screenpipe-app-tauri/src-tauri/src/sidecar.rs
@@ -4,14 +4,14 @@ use crate::permissions::do_permissions_check;
use crate::store::SettingsStore;
use serde::{Deserialize, Serialize};
use std::sync::Arc;
-use tauri::{Manager, State};
+use tauri::State;
use tokio::sync::Mutex;
-use tracing::{debug, error, info, warn};
+use tracing::{debug, info, warn};
/// State holding the embedded server handle
pub struct SidecarState(pub Arc<Mutex<Option<EmbeddedServerHandle>>>);
-#[derive(Debug, Serialize, Deserialize, Clone)]
+#[derive(Debug, Serialize, Deserialize, Clone, specta::Type)]
#[serde(rename_all = "camelCase")]
pub struct MonitorDevice {
pub id: u32,
@@ -21,6 +21,51 @@ pub struct MonitorDevice {
pub height: u32,
}
+#[derive(Debug, Serialize, Deserialize, Clone, specta::Type)]
+#[serde(rename_all = "camelCase")]
+pub struct AudioDeviceInfo {
+ pub name: String,
+ pub is_default: bool,
+}
+
+/// Get all available audio devices
+pub async fn get_available_audio_devices() -> Result<Vec<AudioDeviceInfo>, String> {
+ debug!("Getting available audio devices");
+
+ let devices = screenpipe_audio::core::device::list_audio_devices()
+ .await
+ .map_err(|e| format!("Failed to list audio devices: {}", e))?;
+
+ let default_input = screenpipe_audio::core::device::default_input_device()
+ .map(|d| d.to_string())
+ .ok();
+ let default_output = screenpipe_audio::core::device::default_output_device()
+ .await
+ .map(|d| d.to_string())
+ .ok();
+
+ let result: Vec<AudioDeviceInfo> = devices
+ .iter()
+ .map(|d| {
+ let name = d.to_string();
+ let is_default = Some(&name) == default_input.as_ref() || Some(&name) == default_output.as_ref();
+ AudioDeviceInfo {
+ name,
+ is_default,
+ }
+ })
+ .collect();
+
+ debug!("Found {} audio devices", result.len());
+ Ok(result)
+}
+
+#[tauri::command]
+#[specta::specta]
+pub async fn get_audio_devices() -> Result<Vec<AudioDeviceInfo>, String> {
+ get_available_audio_devices().await
+}
+
/// Get all available monitors connected to the device
pub async fn get_available_monitors() -> Result<Vec<MonitorDevice>, String> {
debug!("Getting available monitors");
@@ -36,7 +81,7 @@ pub async fn get_available_monitors() -> Result<Vec<MonitorDevice>, String> {
.enumerate()
.map(|(i, m)| MonitorDevice {
id: m.id(),
- name: m.name().unwrap_or_else(|| format!("Monitor {}", i + 1)),
+ name: if m.name().is_empty() { format!("Monitor {}", i + 1) } else { m.name().to_string() },
is_default: i == 0, // First monitor is default
width: m.width(),
height: m.height(),
diff --git a/screenpipe-app-tauri/src-tauri/src/store.rs b/screenpipe-app-tauri/src-tauri/src/store.rs
index 2e8229ef3..aac09e30a 100644
--- a/screenpipe-app-tauri/src-tauri/src/store.rs
+++ b/screenpipe-app-tauri/src-tauri/src/store.rs
@@ -506,6 +506,7 @@ impl SettingsStore {
}
}
+ #[allow(dead_code)]
pub fn update(app: &AppHandle, update: impl FnOnce(&mut SettingsStore)) -> Result<(), String> {
let Ok(store) = get_store(app, None) else {
return Err("Failed to get store".to_string());
diff --git a/screenpipe-js/ai-proxy/src/providers/vertex.ts b/screenpipe-js/ai-proxy/src/providers/vertex.ts
index 4969557f9..780f77931 100644
--- a/screenpipe-js/ai-proxy/src/providers/vertex.ts
+++ b/screenpipe-js/ai-proxy/src/providers/vertex.ts
@@ -550,6 +550,29 @@ function sanitizeContent(content: any): any {
return content;
}
+/**
+ * Recursively unwrap nested text objects until we get a string
+ */
+function unwrapText(text: any, depth: number = 0): string {
+ // Prevent infinite recursion
+ if (depth > 10) {
+ console.log('proxyToVertex: unwrapText max depth reached');
+ return String(text);
+ }
+
+ // If already a string, return it
+ if (typeof text === 'string') return text;
+
+ // If it's an object with a text property, unwrap it
+ if (text && typeof text === 'object' && 'text' in text) {
+ console.log('proxyToVertex: unwrapping nested text at depth', depth);
+ return unwrapText(text.text, depth + 1);
+ }
+
+ // Otherwise stringify it
+ return String(text);
+}
+
/**
* Sanitize a single content block
* Fixes nested text issues like: {type: 'text', text: {text: '...'}}
@@ -559,14 +582,11 @@ function sanitizeContentBlock(block: any): any {
// Fix nested text issue: {type: 'text', text: {text: '...'}}
if (block.type === 'text' && block.text !== undefined) {
- // If text is an object with a text property, unwrap it
- if (typeof block.text === 'object' && block.text !== null && 'text' in block.text) {
- console.log('proxyToVertex: fixing nested text.text structure');
- block.text = block.text.text;
- }
- // Ensure text is a string
- if (typeof block.text !== 'string') {
- block.text = String(block.text);
+ // Recursively unwrap nested text objects
+ const originalText = block.text;
+ block.text = unwrapText(block.text);
+ if (originalText !== block.text) {
+ console.log('proxyToVertex: fixed text from', JSON.stringify(originalText), 'to', JSON.stringify(block.text));
}
}
@@ -624,11 +644,21 @@ export async function proxyToVertex(
};
console.log('proxyToVertex: model=', body.model, 'stream=', body.stream, 'messages count=', body.messages?.length);
+ // Debug: log message structure before sanitization
+ if (body.messages && body.messages.length > 0) {
+ console.log('proxyToVertex: BEFORE sanitization, message[2] content:', JSON.stringify(body.messages[2]?.content, null, 2));
+ }
+
// Sanitize messages to fix common formatting issues
if (body.messages) {
body.messages = sanitizeMessages(body.messages);
}
+ // Debug: log message structure after sanitization
+ if (body.messages && body.messages.length > 0) {
+ console.log('proxyToVertex: AFTER sanitization, message[2] content:', JSON.stringify(body.messages[2]?.content, null, 2));
+ }
+
const isStreaming = body.stream === true;
// Get access token
diff --git a/screenpipe-vision/src/capture_screenshot_by_window.rs b/screenpipe-vision/src/capture_screenshot_by_window.rs
index 871dbce24..09590cff8 100644
--- a/screenpipe-vision/src/capture_screenshot_by_window.rs
+++ b/screenpipe-vision/src/capture_screenshot_by_window.rs
@@ -662,14 +662,17 @@ pub async fn capture_all_visible_windows(
.iter()
.any(|&browser| app_name.to_lowercase().contains(browser));
- if is_browser && browser_url.is_none() && !is_focused
- && window_filters.is_title_suggesting_blocked_url(&window_name) {
- tracing::info!(
- "Privacy filter: Skipping unfocused browser window with suspicious title: {}",
- window_name
- );
- continue;
- }
+ if is_browser
+ && browser_url.is_none()
+ && !is_focused
+ && window_filters.is_title_suggesting_blocked_url(&window_name)
+ {
+ tracing::info!(
+ "Privacy filter: Skipping unfocused browser window with suspicious title: {}",
+ window_name
+ );
+ continue;
+ }
all_captured_images.push(CapturedWindow {
image,