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(pipe): added a new pipe to automatically analyze the screen data and notify the user for any potential security threat
bhupesh-sfd745725eeeb9
diff --git a/examples/typescript/pipe-security-check/README.md b/examples/typescript/pipe-security-check/README.mdnew file mode 100644index 000000000..19b37d2c4--- /dev/null+++ b/examples/typescript/pipe-security-check/README.md@@ -0,0 +1,94 @@++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-tagging-activity++this is an experimental, but official pipe, that will use ollama + phi3.5 to annotate your screen data (only OCR) every 1 min++soon we'll make is easier to search through these annotations / tags but in the meantime you can you use to enrich your data++and AI will be able to provide you more relevant answers++this is how you run it through the app:++```bash+ollama run phi3.5+```++click "install"++wait a few minutes then ask AI "read my data from last 5 minutes and list tags you see"+++### tech details++we run deno runtime (a JS/TS engine) within the rust code, which host your pipes, its 99.9% similar to normal JS code++### dev mode++if you're in dev mode you can run the cli like this:++```bash+screenpipe --pipe https://github.com/mediar-ai/screenpipe/edit/main/examples/typescript/pipe-tagging-activity/main.js+```++or dev your own pipe:++```bash+screenpipe --pipe myPipe.js+```++please look the code, it's 99% normal JS but there are limitations currently:+- you cannot use dependencies (yet)+- untested with typescript (but will make pipes TS first soon)++i recommend you copy paste the current main.js file into AI and ask some changes for whatever you want to do, make sure to run an infinite loop also++get featured in the pipe store:++<img width="1312" alt="Screenshot 2024-08-27 at 17 06 45" src="https://github.com/user-attachments/assets/b6856bf4-2cfd-4888-be11-ee7baae6b84b">++just ask @louis030195++### what's next for pipes++- use dependencies (like vercel/ai so cool)+- TS+- acess to screenpipe desktop api (e.g. trigger notifications, customise what cursor-like @ are in the chat, etc.)+- easier to publish your pipes (like obsidian store)+- everything frictionless, effortless, and maximize the value you get out of screenpipe+++++++++++++diff --git a/examples/typescript/pipe-security-check/main.js b/examples/typescript/pipe-security-check/main.jsnew file mode 100644index 000000000..88ef8e29b--- /dev/null+++ b/examples/typescript/pipe-security-check/main.js@@ -0,0 +1,119 @@+const INTERVAL = 1 * 60 * 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 = "Hermes-llama-3.1:latest";+ return { provider, model };+}++async function checkSecurity(provider, screenData) {+ const prompt = `Act like a cybersecurity expert with 10 years of experience detecting suspicious activity. Analyze the following screen data and determine if a security issue is present.++Instructions:+ Analyze the screen data for suspicious activity.+ Output a JSON object:++ {+ "securityIssueFound": true, // or false+ "reason": "Specify the reason for the issue"+ "summary": "One-sentence summary of the security threat"+ }+ Input:+ ${JSON.stringify(screenData)}+ Output only the JSON object.`;++ try {+ const result = await pipe.post(+ "http://localhost:10001/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;+ console.log("AI answer content:", content);+ return JSON.parse(content);+ } catch (error) {+ console.error("Error in AI Response:", error);+ }+}++async function checkRecentActivities(provider) {+ const now = new Date();+ const oneMinuteAgo = new Date(now.getTime() - INTERVAL);++ const screenData = await queryScreenpipe({+ start_time: oneMinuteAgo.toISOString(),+ end_time: now.toISOString(),+ limit: 5,+ content_type: "ocr",+ });++// console.log("Screenpipe data:", screenData);++ if (!screenData || !screenData.data || screenData.data.length === 0) {+ console.log("No data retrieved from Screenpipe");+ return;+ }++ const response = await checkSecurity(provider, screenData);+ console.log("Security check for recent activities response: ", response);+ if (response.securityIssueFound) {+ console.error("Security issue detected", response.reason);+ // pipe.sendNotification("Security issue detected", response.reason);+ } else {+ console.log("No security issue detected");+ }+}++async function runSecurityChecker() {+ const provider = await getAIProvider();+ console.log("Starting Security Checker with provider:", provider);++ while (true) {+ try {+ await checkRecentActivities(provider);+ } catch (error) {+ // pipe.sendNotification({title: "Error in security check", body: error.message})+ console.error("Error in security check of activity:", error);+ }+ await new Promise(resolve => setTimeout(resolve, INTERVAL));+ }+}++// Self-invoking async function to run the activity tagger+(async () => {+ try {+ await runSecurityChecker();+ } catch (error) {+ console.error("Fatal error in Activity Tagger:");+ if (error instanceof Error) {+ console.error("Error name:", error.name);+ console.error("Error message:", error.message);+ console.error("Error stack:", error.stack);+ } else {+ console.error("Unexpected error:", error);+ }+ }+})();