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(connections): support POST configuration from agents (#5587)
Louis Beaumontda4eda82ec1e
diff --git a/crates/screenpipe-connect/src/connections/mod.rs b/crates/screenpipe-connect/src/connections/mod.rsindex b4ff8d295..b622eb220 100644--- a/crates/screenpipe-connect/src/connections/mod.rs+++ b/crates/screenpipe-connect/src/connections/mod.rs@@ -429,6 +429,29 @@ pub struct SavedConnection {pub credentials: Map<String, Value>,}+/// Normalize credentials received from API/agent callers before persistence.+///+/// Empty optional fields (for example PostHog's host) are omitted so the+/// proxy's `{field|default}` URL fallback works consistently. Required fields+/// remain validated by the integration's test/proxy paths, while this keeps+/// configuration writes idempotent and tolerant of UI form submissions.+fn normalize_credentials(+ def: &'static IntegrationDef,+ mut credentials: Map<String, Value>,+) -> Result<Map<String, Value>> {+ for field in def.fields {+ let should_remove = credentials+ .get(field.key)+ .and_then(Value::as_str)+ .map(|value| value.trim().is_empty())+ .unwrap_or(false);+ if should_remove {+ credentials.remove(field.key);+ }+ }+ Ok(credentials)+}+fn store_path(screenpipe_dir: &Path) -> PathBuf {screenpipe_dir.join("connections.json")}@@ -614,7 +637,8 @@ impl ConnectionManager {}pub async fn connect(&self, id: &str, creds: Map<String, Value>) -> Result<()> {- self.find(id)?;+ let integration = self.find(id)?;+ let creds = normalize_credentials(integration.def(), creds)?;let conn = SavedConnection {enabled: true,credentials: creds,@@ -710,7 +734,8 @@ impl ConnectionManager {instance: Option<&str>,creds: Map<String, Value>,) -> Result<()> {- self.find(id)?;+ let integration = self.find(id)?;+ let creds = normalize_credentials(integration.def(), creds)?;let key = make_key(id, instance);let conn = SavedConnection {enabled: true,diff --git a/crates/screenpipe-engine/src/connections_api.rs b/crates/screenpipe-engine/src/connections_api.rsindex f5f266253..b682c6549 100644--- a/crates/screenpipe-engine/src/connections_api.rs+++ b/crates/screenpipe-engine/src/connections_api.rs@@ -582,7 +582,7 @@ async fn get_connection(response}-/// PUT /connections/:id — save credentials.+/// PUT/POST /connections/:id — save credentials.async fn connect_integration(State(state): State<ConnectionsState>,Path(id): Path<String>,@@ -3397,7 +3397,12 @@ where.route("/:id",get(get_connection)+ // Keep POST as an alias for agent/tool callers. The UI and+ // older clients use PUT, but the public connection contract+ // describes configuration as POST /connections/:id. Both+ // paths share the same credential-safe handler..put(connect_integration)+ .post(connect_integration).delete(disconnect_integration),).route("/:id/test", post(test_connection))