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(workflow-events): un-orphan the classifier + route through gateway
Louis Beaumont0e4dfcedab60
diff --git a/crates/screenpipe-engine/src/bin/screenpipe-engine.rs b/crates/screenpipe-engine/src/bin/screenpipe-engine.rsindex 698bb0617..1266acdb8 100644--- a/crates/screenpipe-engine/src/bin/screenpipe-engine.rs+++ b/crates/screenpipe-engine/src/bin/screenpipe-engine.rs@@ -1008,7 +1008,31 @@ async fn main() -> anyhow::Result<()> {std::fs::create_dir_all(&pipes_dir).ok();let user_token = std::env::var("SCREENPIPE_API_KEY").ok();- let pi_executor = std::sync::Arc::new(screenpipe_core::agents::pi::PiExecutor::new(user_token));+ let pi_executor = std::sync::Arc::new(screenpipe_core::agents::pi::PiExecutor::new(+ user_token.clone(),+ ));++ // Workflow event classifier — opt-in cloud feature. Polls recent activity+ // and emits `WorkflowEvent`s on the bus so pipes with `trigger.events`+ // frontmatter can run. Routed through the gateway by default; self-host+ // can override with SCREENPIPE_EVENT_CLASSIFIER_URL.+ if config.enable_workflow_events {+ let classifier_url = std::env::var("SCREENPIPE_EVENT_CLASSIFIER_URL")+ .unwrap_or_else(|_| {+ screenpipe_engine::workflow_classifier::DEFAULT_CLASSIFIER_URL.to_string()+ });+ let token = user_token.clone().unwrap_or_default();+ let port = config.port;+ tokio::spawn(async move {+ screenpipe_engine::workflow_classifier::start_workflow_classifier(+ classifier_url,+ token,+ port,+ std::time::Duration::from_secs(30),+ )+ .await;+ });+ }let mut agent_executors: std::collections::HashMap<String,diff --git a/crates/screenpipe-engine/src/workflow_classifier.rs b/crates/screenpipe-engine/src/workflow_classifier.rsindex 706d0bdd3..b60bcf95d 100644--- a/crates/screenpipe-engine/src/workflow_classifier.rs+++ b/crates/screenpipe-engine/src/workflow_classifier.rs@@ -26,9 +26,12 @@ const DEDUP_COOLDOWN: Duration = Duration::from_secs(300);/// System prompt for the cloud classifier.const CLASSIFIER_SYSTEM_PROMPT: &str = r#"You are a desktop activity classifier for screenpipe. Given a sequence of app activities (timestamps, app names, window titles), identify the high-level workflow event happening. Respond with a JSON object: {"event": "event_name", "confidence": 0.0-1.0, "description": "brief explanation"}. If no specific workflow is detected, respond with {"event": "no_event", "confidence": 1.0, "description": "normal activity"}."#;-/// Default vLLM endpoint for the event classifier.-/// Direct to the self-hosted A100 — no Cloudflare Worker overhead.-pub const DEFAULT_CLASSIFIER_URL: &str = "http://34.122.128.37:8080";+/// Default endpoint for the event classifier — routes through the screenpipe+/// AI gateway, which forwards the `screenpipe-event-classifier` model to the+/// self-hosted vLLM. Going through the gateway means infra moves only need a+/// `wrangler secret put EVENT_CLASSIFIER_URL` — no client release.+/// Override with the `SCREENPIPE_EVENT_CLASSIFIER_URL` env var for self-host.+pub const DEFAULT_CLASSIFIER_URL: &str = "https://api.screenpi.pe";/// Start the workflow classifier polling loop.pub async fn start_workflow_classifier(@@ -215,15 +218,19 @@ async fn get_recent_activities(client: &Client, port: u16) -> Option<Vec<Activit}}-/// Call the vLLM classifier directly (self-hosted, no auth needed).+/// Call the classifier through the screenpipe gateway (default) or directly+/// against a self-hosted vLLM (`SCREENPIPE_EVENT_CLASSIFIER_URL` override).+/// The model name `screenpipe-event-classifier` is recognized by both: vLLM+/// exposes it via `--served-model-name`, and the gateway routes it to the+/// vLLM URL stored in its `EVENT_CLASSIFIER_URL` secret.async fn classify(client: &Client,classifier_url: &str,- _token: &str,+ token: &str,activity_text: &str,) -> Result<ClassifierResult, String> {let body = json!({- "model": "/home/louisbeaumont/model/event-classifier-merged",+ "model": "screenpipe-event-classifier","messages": [{"role": "system", "content": CLASSIFIER_SYSTEM_PROMPT},{"role": "user", "content": format!("What workflow event is happening?\n\n{}", activity_text)}@@ -233,8 +240,11 @@ async fn classify("chat_template_kwargs": {"enable_thinking": false}});- let response = client- .post(format!("{}/v1/chat/completions", classifier_url))+ let mut request = client.post(format!("{}/v1/chat/completions", classifier_url));+ if !token.is_empty() {+ request = request.bearer_auth(token);+ }+ let response = request.json(&body).send().awaitdiff --git a/packages/ai-gateway/src/services/usage-tracker.ts b/packages/ai-gateway/src/services/usage-tracker.tsindex 660143807..678273a5e 100644--- a/packages/ai-gateway/src/services/usage-tracker.ts+++ b/packages/ai-gateway/src/services/usage-tracker.ts@@ -465,6 +465,13 @@ export async function getUsageStatus(* Check if a model is allowed for a given tier*/export function isModelAllowed(model: string, tier: UserTier, env?: Env): boolean {+ // Internal zero-cost models (e.g., the workflow event classifier on our+ // own vLLM) are always allowed regardless of tier — we eat the cost and+ // they're gated at the feature level (opt-in setting), not the tier.+ if (model === 'screenpipe-event-classifier') {+ return true;+ }+const allowedModels = getTierConfig(env)[tier].allowedModels;// Subscribed users can use any model