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: add vision sse to sdk
Louis Beaumont1b8fc082d062
diff --git a/screenpipe-js/browser-sdk/package.json b/screenpipe-js/browser-sdk/package.jsonindex bef53c17e..4a26fd0f7 100644--- a/screenpipe-js/browser-sdk/package.json+++ b/screenpipe-js/browser-sdk/package.json@@ -1,6 +1,6 @@{"name": "@screenpipe/browser",- "version": "0.1.13",+ "version": "0.1.14","type": "module","main": "./dist/index.cjs","module": "./dist/index.js",diff --git a/screenpipe-js/browser-sdk/src/index.ts b/screenpipe-js/browser-sdk/src/index.tsindex 6f62bc970..fbe264e08 100644--- a/screenpipe-js/browser-sdk/src/index.ts+++ b/screenpipe-js/browser-sdk/src/index.ts@@ -6,6 +6,8 @@ import type {ScreenpipeResponse,TranscriptionChunk,TranscriptionStreamResponse,+ VisionEvent,+ VisionStreamResponse,} from "../../common/types";import { toSnakeCase, convertToCamelCase } from "../../common/utils";@@ -44,6 +46,9 @@ export interface BrowserPipe {void,unknown>;+ streamVision(+ includeImages?: boolean+ ): AsyncGenerator<VisionStreamResponse, void, unknown>;}// Browser-only implementations@@ -159,6 +164,34 @@ export const pipe: BrowserPipe = {eventSource.close();}},++ async *streamVision(+ includeImages: boolean = false+ ): AsyncGenerator<VisionStreamResponse, void, unknown> {+ const eventSource = new EventSource(+ `http://localhost:3030/sse/vision?images=${includeImages}`+ );++ try {+ while (true) {+ const event: VisionEvent = await new Promise((resolve, reject) => {+ eventSource.onmessage = (event) => {+ resolve(JSON.parse(event.data));+ };+ eventSource.onerror = (error) => {+ reject(error);+ };+ });++ yield {+ type: "vision_stream",+ data: event,+ };+ }+ } finally {+ eventSource.close();+ }+ },};const sendDesktopNotification = pipe.sendDesktopNotification;diff --git a/screenpipe-js/common/types.ts b/screenpipe-js/common/types.tsindex 3b8fa2843..464253633 100644--- a/screenpipe-js/common/types.ts+++ b/screenpipe-js/common/types.ts@@ -244,3 +244,16 @@ export interface TranscriptionStreamResponse {finish_reason: null | "stop";}[];}++export interface VisionEvent {+ image?: string; // base64 encoded image+ text: string;+ timestamp: string;+ app_name?: string;+ window_name?: string;+}++export interface VisionStreamResponse {+ type: string;+ data: VisionEvent;+}diff --git a/screenpipe-js/node-sdk/package.json b/screenpipe-js/node-sdk/package.jsonindex 417332b31..1613f3811 100644--- a/screenpipe-js/node-sdk/package.json+++ b/screenpipe-js/node-sdk/package.json@@ -1,6 +1,6 @@{"name": "@screenpipe/js",- "version": "1.0.2",+ "version": "1.0.3","type": "module","main": "./dist/index.cjs","module": "./dist/index.js",diff --git a/screenpipe-js/node-sdk/src/index.ts b/screenpipe-js/node-sdk/src/index.tsindex f25592537..8ed5c195e 100644--- a/screenpipe-js/node-sdk/src/index.ts+++ b/screenpipe-js/node-sdk/src/index.ts@@ -9,6 +9,8 @@ import type {ScreenpipeResponse,TranscriptionStreamResponse,TranscriptionChunk,+ VisionEvent,+ VisionStreamResponse,} from "../../common/types";import {toSnakeCase,@@ -176,6 +178,35 @@ class NodePipe {eventSource.close();}}++ public async *streamVision(+ includeImages: boolean = false+ ): AsyncGenerator<VisionStreamResponse, void, unknown> {+ const apiUrl = process.env.SCREENPIPE_SERVER_URL || "http://localhost:3030";+ const eventSource = new EventSource(+ `${apiUrl}/sse/vision?images=${includeImages}`+ );++ try {+ while (true) {+ const event: VisionEvent = await new Promise((resolve, reject) => {+ eventSource.onmessage = (event) => {+ resolve(JSON.parse(event.data));+ };+ eventSource.onerror = (error) => {+ reject(error);+ };+ });++ yield {+ type: "vision_stream",+ data: event,+ };+ }+ } finally {+ eventSource.close();+ }+ }}const pipe = new NodePipe();diff --git a/screenpipe-js/node-sdk/tests/streamVision.test.ts b/screenpipe-js/node-sdk/tests/streamVision.test.tsnew file mode 100644index 000000000..18e425f3f--- /dev/null+++ b/screenpipe-js/node-sdk/tests/streamVision.test.ts@@ -0,0 +1,57 @@+import { describe, expect, test } from "bun:test";+import { pipe } from "../src/index";++describe("streamVision", () => {+ test(+ "should receive and format vision events without images",+ async () => {+ const events = [];++ for await (const event of pipe.streamVision()) {+ events.push(event);+ if (events.length === 2) break; // Break after receiving two events+ }++ expect(events).toHaveLength(2);++ // verify event format+ expect(events[0]).toHaveProperty("type", "vision_stream");+ expect(events[0].data).toHaveProperty("text");+ expect(events[0].data).toHaveProperty("timestamp");+ expect(events[0].data.image || undefined).toBeUndefined(); // images disabled by default+ },+ { timeout: 15_000 }+ );++ test(+ "should receive and format vision events with images",+ async () => {+ const events = [];++ for await (const event of pipe.streamVision(true)) {+ events.push(event);+ if (events.length === 2) break; // Break after receiving two events+ }++ expect(events).toHaveLength(2);++ // verify event format with images+ expect(events[0]).toHaveProperty("type", "vision_stream");+ expect(events[0].data).toHaveProperty("text");+ expect(events[0].data).toHaveProperty("timestamp");+ expect(events[0].data).toHaveProperty("image");+ expect(typeof events[0].data.image).toBe("string");+ },+ { timeout: 10_000 }+ );++ test("should handle server errors gracefully", async () => {+ try {+ const generator = pipe.streamVision();+ await generator.next();+ expect(true).toBe(false); // should not reach here+ } catch (error) {+ expect(error).toBeDefined();+ }+ });+});diff --git a/screenpipe-vision/bin/ui_monitor b/screenpipe-vision/bin/ui_monitorindex c18230ba8..602bde837 100755Binary files a/screenpipe-vision/bin/ui_monitor and b/screenpipe-vision/bin/ui_monitor differdiff --git a/screenpipe-vision/bin/ui_monitor-aarch64-apple-darwin b/screenpipe-vision/bin/ui_monitor-aarch64-apple-darwinindex c18230ba8..602bde837 100755Binary files a/screenpipe-vision/bin/ui_monitor-aarch64-apple-darwin and b/screenpipe-vision/bin/ui_monitor-aarch64-apple-darwin differ