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: send frame_ids via WebSocket message to avoid URL length limits
Louis Beaumont860d294d6252
diff --git a/pipes/rewind/src/components/export-button.tsx b/pipes/rewind/src/components/export-button.tsxindex c4c40d349..a61706a06 100644--- a/pipes/rewind/src/components/export-button.tsx+++ b/pipes/rewind/src/components/export-button.tsx@@ -51,9 +51,9 @@ export function ExportButton() {ws = null;};- // Create WebSocket connection+ // Create WebSocket connection - send frame_ids in message body to avoid URL length limitsws = new WebSocket(- `ws://localhost:3030/frames/export?frame_ids=${sortedFrameIds.join(",")}&fps=${settings.fps ?? 0.5}`,+ `ws://localhost:3030/frames/export?fps=${settings.fps ?? 0.5}`,);// Set a timeout to handle connection issues@@ -73,6 +73,8 @@ export function ExportButton() {ws.onopen = () => {clearTimeout(connectionTimeout);console.log("WebSocket connection established");+ // Send frame_ids in message body to avoid URL length limits+ ws?.send(JSON.stringify({ frame_ids: sortedFrameIds.map(id => parseInt(id)) }));};ws.onmessage = async (event) => {diff --git a/screenpipe-app-tauri/components/global-chat.tsx b/screenpipe-app-tauri/components/global-chat.tsxindex d714e68fd..551ddfe1e 100644--- a/screenpipe-app-tauri/components/global-chat.tsx+++ b/screenpipe-app-tauri/components/global-chat.tsx@@ -569,8 +569,9 @@ export function GlobalChat() {ws = null;};+ // Send frame_ids in message body to avoid URL length limitsws = new WebSocket(- `ws://localhost:3030/frames/export?frame_ids=${sortedFrameIds.join(",")}&fps=${settings.fps ?? 0.5}`,+ `ws://localhost:3030/frames/export?fps=${settings.fps ?? 0.5}`,);const connectionTimeout = setTimeout(() => {@@ -582,7 +583,11 @@ export function GlobalChat() {}}, 10000);- ws.onopen = () => clearTimeout(connectionTimeout);+ ws.onopen = () => {+ clearTimeout(connectionTimeout);+ // Send frame_ids in message body to avoid URL length limits+ ws?.send(JSON.stringify({ frame_ids: sortedFrameIds.map(id => parseInt(id)) }));+ };ws.onmessage = async (event) => {try {diff --git a/screenpipe-app-tauri/components/rewind/export-button.tsx b/screenpipe-app-tauri/components/rewind/export-button.tsxindex 455514a7f..5ae4e9045 100644--- a/screenpipe-app-tauri/components/rewind/export-button.tsx+++ b/screenpipe-app-tauri/components/rewind/export-button.tsx@@ -56,9 +56,9 @@ export function ExportButton() {ws = null;};- // Create WebSocket connection+ // Create WebSocket connection - send frame_ids in message body to avoid URL length limitsws = new WebSocket(- `ws://localhost:3030/frames/export?frame_ids=${sortedFrameIds.join(",")}&fps=${settings.fps ?? 0.5}`,+ `ws://localhost:3030/frames/export?fps=${settings.fps ?? 0.5}`,);// Set a timeout to handle connection issues@@ -78,6 +78,8 @@ export function ExportButton() {ws.onopen = () => {clearTimeout(connectionTimeout);console.log("WebSocket connection established");+ // Send frame_ids in message body to avoid URL length limits+ ws?.send(JSON.stringify({ frame_ids: sortedFrameIds.map(id => parseInt(id)) }));};ws.onmessage = async (event) => {diff --git a/screenpipe-integrations/screenpipe-mcp/src/index.ts b/screenpipe-integrations/screenpipe-mcp/src/index.tsindex e9d2d5e6e..e141a989d 100644--- a/screenpipe-integrations/screenpipe-mcp/src/index.ts+++ b/screenpipe-integrations/screenpipe-mcp/src/index.ts@@ -638,7 +638,8 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {frameIds.sort((a, b) => a - b);// Step 2: Connect to WebSocket and export video- const wsUrl = `ws://localhost:${port}/frames/export?frame_ids=${frameIds.join(",")}&fps=${fps}`;+ // Send frame_ids in message body to avoid URL length limits+ const wsUrl = `ws://localhost:${port}/frames/export?fps=${fps}`;const exportResult = await new Promise<{success: boolean;@@ -657,6 +658,11 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {}}, 5 * 60 * 1000); // 5 minute timeout+ ws.on("open", () => {+ // Send frame_ids in message body to avoid URL length limits+ ws.send(JSON.stringify({ frame_ids: frameIds }));+ });+ws.on("error", (error) => {if (!resolved) {resolved = true;diff --git a/screenpipe-server/src/server.rs b/screenpipe-server/src/server.rsindex 38f95e6f1..de3012c7a 100644--- a/screenpipe-server/src/server.rs+++ b/screenpipe-server/src/server.rs@@ -2383,11 +2383,37 @@ async fn handle_health_socket(#[derive(Debug, Deserialize)]#[serde(rename_all = "snake_case")]pub struct VideoExportRequest {- #[serde(deserialize_with = "deserialize_frame_ids")]+ #[serde(default, deserialize_with = "deserialize_frame_ids_optional")]frame_ids: Vec<i64>,+ #[serde(default = "default_fps")]fps: f64,}+fn default_fps() -> f64 {+ 0.5+}++fn deserialize_frame_ids_optional<'de, D>(deserializer: D) -> Result<Vec<i64>, D::Error>+where+ D: serde::Deserializer<'de>,+{+ let s: Option<String> = Option::deserialize(deserializer)?;+ match s {+ Some(s) if !s.is_empty() => s+ .split(',')+ .map(|id| id.trim().parse::<i64>())+ .collect::<Result<Vec<_>, _>>()+ .map_err(serde::de::Error::custom),+ _ => Ok(Vec::new()),+ }+}++/// Message sent by client with frame IDs (for when URL would be too long)+#[derive(Debug, Deserialize)]+struct VideoExportMessage {+ frame_ids: Vec<i64>,+}+#[derive(OaSchema, Debug, Deserialize)]#[serde(rename_all = "snake_case")]struct AudioDeviceControlRequest {@@ -2453,13 +2479,6 @@ async fn stop_audio_device(}))}-fn deserialize_frame_ids<'de, D>(deserializer: D) -> Result<Vec<i64>, D::Error>-where- D: serde::Deserializer<'de>,-{- let s: String = String::deserialize(deserializer)?;- Ok(s.split(',').filter_map(|id| id.parse().ok()).collect())-}#[derive(Debug, Serialize)]struct ExportProgress {@@ -2506,15 +2525,8 @@ pub async fn handle_video_export_ws(State(state): State<Arc<AppState>>,Query(payload): Query<VideoExportRequest>,) -> Response {- if payload.frame_ids.is_empty() {- return (- StatusCode::BAD_REQUEST,- Json(json!({ "error": "No valid frame IDs provided" })),- )- .into_response();- }-// Check connection limit before upgrading+ // Frame IDs can be empty - they'll be sent via WebSocket messagematch try_acquire_ws_connection(&state.ws_connection_count) {Some(guard) => ws.on_upgrade(move |socket| async move {@@ -2531,9 +2543,95 @@ pub async fn handle_video_export_ws(async fn handle_video_export(mut socket: WebSocket,state: Arc<AppState>,- payload: VideoExportRequest,+ mut payload: VideoExportRequest,_guard: WsConnectionGuard,) {+ // If frame_ids not provided in URL, wait for them via WebSocket message+ if payload.frame_ids.is_empty() {+ info!("No frame_ids in URL, waiting for WebSocket message...");+ // Wait for frame_ids message with timeout+ let timeout = tokio::time::timeout(+ std::time::Duration::from_secs(30),+ socket.recv()+ ).await;++ match timeout {+ Ok(Some(Ok(Message::Text(text)))) => {+ match serde_json::from_str::<VideoExportMessage>(&text) {+ Ok(msg) => {+ info!("Received {} frame_ids via WebSocket message", msg.frame_ids.len());+ payload.frame_ids = msg.frame_ids;+ }+ Err(e) => {+ let _ = socket+ .send(Message::Text(+ serde_json::to_string(&ExportProgress {+ status: "error".to_string(),+ progress: 0.0,+ video_data: None,+ error: Some(format!("Invalid frame_ids message: {}", e)),+ })+ .unwrap_or_default(),+ ))+ .await;+ return;+ }+ }+ }+ Ok(Some(Ok(_))) => {+ let _ = socket+ .send(Message::Text(+ serde_json::to_string(&ExportProgress {+ status: "error".to_string(),+ progress: 0.0,+ video_data: None,+ error: Some("Expected text message with frame_ids".to_string()),+ })+ .unwrap_or_default(),+ ))+ .await;+ return;+ }+ Ok(Some(Err(e))) => {+ error!("WebSocket error receiving frame_ids: {}", e);+ return;+ }+ Ok(None) => {+ error!("WebSocket closed before receiving frame_ids");+ return;+ }+ Err(_) => {+ let _ = socket+ .send(Message::Text(+ serde_json::to_string(&ExportProgress {+ status: "error".to_string(),+ progress: 0.0,+ video_data: None,+ error: Some("Timeout waiting for frame_ids".to_string()),+ })+ .unwrap_or_default(),+ ))+ .await;+ return;+ }+ }+ }++ if payload.frame_ids.is_empty() {+ let _ = socket+ .send(Message::Text(+ serde_json::to_string(&ExportProgress {+ status: "error".to_string(),+ progress: 0.0,+ video_data: None,+ error: Some("No valid frame IDs provided".to_string()),+ })+ .unwrap_or_default(),+ ))+ .await;+ return;+ }+let temp_dir = match tempfile::tempdir() {Ok(dir) => dir,Err(e) => {