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: phi3.5 looks at your screen and send notification when distracted
Louis Beaumont83d1fb3b037d
diff --git a/examples/typescript/pipe-focus-notification-buddy/README.md b/examples/typescript/pipe-focus-notification-buddy/README.mdnew file mode 100644index 000000000..05d8fb4dc--- /dev/null+++ b/examples/typescript/pipe-focus-notification-buddy/README.md@@ -0,0 +1,38 @@++https://github.com/user-attachments/assets/795dfd91-393a-4eef-a20b-5b2c35d594f9++in screenpipe we have a plugin system called "pipe store" or "pipes"++think of it like this:++screenpipe data -> your pipe like "AI annotate" or "send to salesforce"++a more dev-friendly explanation:++screenpipe | AI tag | notion update++or++screenpipe | AI tag | slack send report++or++screenpipe | fill salesforce++or++screenpipe | logs daily++basically it would read, process, annotate, analyse, summarize, send, your data customisable to your desire, effortlessly++### pipe-sync-meetings-to-notion++this is an experimental, but official pipe++this is how you run it through the app:++`ollama run phi3.5`++then drop the url of this folder in the pipe store and it works++works also with CLI using `--pipe path/to/pipe.js`diff --git a/examples/typescript/pipe-focus-notification-buddy/main.js b/examples/typescript/pipe-focus-notification-buddy/main.jsnew file mode 100644index 000000000..329fde001--- /dev/null+++ b/examples/typescript/pipe-focus-notification-buddy/main.js@@ -0,0 +1,97 @@+const INTERVAL = 1 * 6 * 1000; // 1 minute in milliseconds++async function queryScreenpipe(params) {+ try {+ const queryParams = Object.entries(params)+ .filter(([_, v]) => v != null)+ .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`)+ .join('&');+ console.log("Calling Screenpipe:", JSON.stringify(params));+ const result = await pipe.get(`http://localhost:3030/search?${queryParams}`);+ console.log("Retrieved", result.data.length, "items from Screenpipe");+ return result;+ } catch (error) {+ console.error("Error querying Screenpipe:", error);+ return null;+ }+}++async function getAIProvider() {+ const provider = "ollama";+ const model = "phi3.5";+ return { provider, model };+}++async function detectWorkStatus(provider, screenData) {+ const prompt = `Based on the following screen data, determine if the user is working or not:++ ${JSON.stringify(screenData)}++ We will show a desktop notification if the user is not working.+ Not working:+ - Social media+ - Chatting+ - Youtube+ - Netflix+ - Games+ - Porn+ - Other distracting websites++ Be funny, sarcastic, like say "stop watching porn bro", use techbro language. Keep body short as it's a notification.++ Return a JSON object with the following structure:+ {+ "work": boolean,+ "title": "A brief title with advice or support",+ "body": "A brief message with advice or support"+ }+ Do not say anything else but JSON.`;++ const result = await pipe.post(+ "http://localhost:11434/api/chat",+ JSON.stringify({+ model: provider.model,+ messages: [{ role: "user", content: prompt }],+ response_format: { type: "json_object" },+ stream: false,+ }),+ );++ console.log("AI answer:", result);++ const content = result.message.content;+ return JSON.parse(content);+}++async function main() {+ const provider = await getAIProvider();++ while (true) {+ try {+ const screenData = await queryScreenpipe({+ limit: 10,+ offset: 0,+ start_time: new Date(Date.now() - INTERVAL).toISOString(),+ end_time: new Date().toISOString(),+ content_type: "ocr",+ });++ if (screenData && screenData.data) {+ const workStatus = await detectWorkStatus(provider, screenData.data);++ if (!workStatus.work) {+ pipe.sendNotification({+ title: workStatus.title,+ body: workStatus.body,+ });+ }+ }+ } catch (error) {+ console.error("Error in main loop:", error);+ }++ await new Promise(resolve => setTimeout(resolve, INTERVAL));+ }+}++main();\ No newline at end of filediff --git a/screenpipe-core/src/deno/runtime.js b/screenpipe-core/src/deno/runtime.jsindex 4dbeac9bd..2b24a2a1e 100644--- a/screenpipe-core/src/deno/runtime.js+++ b/screenpipe-core/src/deno/runtime.js@@ -56,8 +56,16 @@ const pipe = {throw error;}},- sendNotification: (title, body) => {- return pipe.post("http://localhost:11435/notify", { title, body });+ sendNotification: async ({ title, body }) => {+ const response = await ops.op_fetch("http://localhost:11435/notify", {+ headers: {+ "Content-Type": "application/json",+ },+ method: "POST",+ body: JSON.stringify({ title, body })+ });+ console.log("Notification sent:", response);+ return JSON.parse(response);},};diff --git a/screenpipe-core/src/pipes.rs b/screenpipe-core/src/pipes.rsindex a1d77c252..81181fda6 100644--- a/screenpipe-core/src/pipes.rs+++ b/screenpipe-core/src/pipes.rs@@ -259,9 +259,7 @@ mod pipes {..Default::default()});- // add all env var starting with SCREENPIPE_ to the global scope in process.env-- // first init the process.env object+ // Initialize process.envjs_runtime.execute_script("main", "globalThis.process = { env: {} }")?;for (key, value) in env::vars() {@@ -272,9 +270,28 @@ mod pipes {}let mod_id = js_runtime.load_main_es_module(&main_module).await?;- let result = js_runtime.mod_evaluate(mod_id);- js_runtime.run_event_loop(Default::default()).await?;- result.await+ let evaluate_future = js_runtime.mod_evaluate(mod_id);++ // Run the event loop and handle potential errors+ match js_runtime.run_event_loop(Default::default()).await {+ Ok(_) => (),+ Err(e) => {+ error!("Error in JavaScript runtime event loop: {}", e);+ // ! avoid crashing screenpipe if pipes broken+ // You can choose to return the error or handle it differently+ // return Err(anyhow::anyhow!("JavaScript runtime error: {}", e));+ }+ }++ // Evaluate the module and handle potential errors+ match evaluate_future.await {+ Ok(_) => Ok(()),+ Err(e) => {+ error!("Error evaluating JavaScript module: {}", e);+ // You can choose to return the error or handle it differently+ Err(anyhow::anyhow!("JavaScript module evaluation error: {}", e))+ }+ }}}