Skip to content

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

feat: add see transcription to sdk

Louis Beaumont3e8f503fdf57
diff --git a/screenpipe-js/browser-sdk/bun.lockb b/screenpipe-js/browser-sdk/bun.lockb
new file mode 100755
index 000000000..09bb18ef7
Binary files /dev/null and b/screenpipe-js/browser-sdk/bun.lockb differ
diff --git a/screenpipe-js/browser-sdk/package.json b/screenpipe-js/browser-sdk/package.json
index 4cf0b0fa8..bef53c17e 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.12",
+ "version": "0.1.13",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
@@ -24,6 +24,7 @@
"@types/express": "^5.0.0",
"@types/node-cron": "^3.0.11",
"@types/uuid": "^10.0.0",
+ "eventsource": "^3.0.2",
"express": "^4.21.1",
"node-cron": "^3.0.3"
},
@@ -39,4 +40,4 @@
"browser": ["./dist/browser.d.ts"]
}
}
-}
\ No newline at end of file
+}
diff --git a/screenpipe-js/browser-sdk/src/index.ts b/screenpipe-js/browser-sdk/src/index.ts
index 3e698bd2c..6f62bc970 100644
--- a/screenpipe-js/browser-sdk/src/index.ts
+++ b/screenpipe-js/browser-sdk/src/index.ts
@@ -4,6 +4,8 @@ import type {
NotificationOptions,
ScreenpipeQueryParams,
ScreenpipeResponse,
+ TranscriptionChunk,
+ TranscriptionStreamResponse,
} from "../../common/types";
import { toSnakeCase, convertToCamelCase } from "../../common/utils";
@@ -37,6 +39,11 @@ export interface BrowserPipe {
moveMouse: (x: number, y: number) => Promise<boolean>;
click: (button: "left" | "right" | "middle") => Promise<boolean>;
};
+ streamTranscriptions(): AsyncGenerator<
+ TranscriptionStreamResponse,
+ void,
+ unknown
+ >;
}
// Browser-only implementations
@@ -111,6 +118,47 @@ export const pipe: BrowserPipe = {
click: (button: "left" | "right" | "middle") =>
sendInputControl({ type: "MouseClick", data: button }),
},
+
+ async *streamTranscriptions(): AsyncGenerator<
+ TranscriptionStreamResponse,
+ void,
+ unknown
+ > {
+ const eventSource = new EventSource(
+ "http://localhost:3030/sse/transcriptions"
+ );
+
+ try {
+ while (true) {
+ const chunk: TranscriptionChunk = await new Promise(
+ (resolve, reject) => {
+ eventSource.onmessage = (event) => {
+ resolve(JSON.parse(event.data));
+ };
+ eventSource.onerror = (error) => {
+ reject(error);
+ };
+ }
+ );
+
+ yield {
+ id: crypto.randomUUID(),
+ object: "text_completion_chunk",
+ created: Date.now(),
+ model: "screenpipe-realtime",
+ choices: [
+ {
+ text: chunk.text,
+ index: 0,
+ finish_reason: chunk.is_final ? "stop" : null,
+ },
+ ],
+ };
+ }
+ } finally {
+ eventSource.close();
+ }
+ },
};
const sendDesktopNotification = pipe.sendDesktopNotification;
@@ -118,5 +166,9 @@ const queryScreenpipe = pipe.queryScreenpipe;
const input = pipe.input;
export { sendDesktopNotification, queryScreenpipe, input };
-export { toCamelCase, toSnakeCase, convertToCamelCase } from "../../common/utils";
+export {
+ toCamelCase,
+ toSnakeCase,
+ convertToCamelCase,
+} from "../../common/utils";
export * from "../../common/types";
diff --git a/screenpipe-js/common/types.ts b/screenpipe-js/common/types.ts
index f0fe15024..3b8fa2843 100644
--- a/screenpipe-js/common/types.ts
+++ b/screenpipe-js/common/types.ts
@@ -224,3 +224,23 @@ export interface ParsedConfig<T = unknown> {
default?: T;
}[];
}
+
+export interface TranscriptionChunk {
+ text: string;
+ timestamp: string; // ISO string
+ device_name: string;
+ device_type: "input" | "output";
+ is_final: boolean;
+}
+
+export interface TranscriptionStreamResponse {
+ id: string;
+ object: "text_completion_chunk";
+ created: number;
+ model: "screenpipe-realtime";
+ choices: {
+ text: string;
+ index: number;
+ finish_reason: null | "stop";
+ }[];
+}
diff --git a/screenpipe-js/node-sdk/bun.lockb b/screenpipe-js/node-sdk/bun.lockb
index 22b3dc280..21d5db97e 100755
Binary files a/screenpipe-js/node-sdk/bun.lockb and b/screenpipe-js/node-sdk/bun.lockb differ
diff --git a/screenpipe-js/node-sdk/package.json b/screenpipe-js/node-sdk/package.json
index 0b6a1d3e0..417332b31 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.1",
+ "version": "1.0.2",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
@@ -24,6 +24,7 @@
"@types/express": "^5.0.0",
"@types/node-cron": "^3.0.11",
"@types/uuid": "^10.0.0",
+ "eventsource": "^3.0.2",
"express": "^4.21.1",
"node-cron": "^3.0.3"
},
diff --git a/screenpipe-js/node-sdk/src/index.ts b/screenpipe-js/node-sdk/src/index.ts
index 9c8aa1fc9..f25592537 100644
--- a/screenpipe-js/node-sdk/src/index.ts
+++ b/screenpipe-js/node-sdk/src/index.ts
@@ -7,17 +7,25 @@ import type {
InputControlResponse,
ScreenpipeQueryParams,
ScreenpipeResponse,
+ TranscriptionStreamResponse,
+ TranscriptionChunk,
} from "../../common/types";
-import { toSnakeCase, convertToCamelCase, toCamelCase } from "../../common/utils";
+import {
+ toSnakeCase,
+ convertToCamelCase,
+ toCamelCase,
+} from "../../common/utils";
import { SettingsManager } from "./SettingsManger";
import { Scheduler } from "./Scheduler";
import { InboxManager } from "./InboxManager";
-
+import { EventSource } from "eventsource";
class NodePipe {
public input = {
- type: (text: string) => this.sendInputControl({ type: "WriteText", data: text }),
- press: (key: string) => this.sendInputControl({ type: "KeyPress", data: key }),
+ type: (text: string) =>
+ this.sendInputControl({ type: "WriteText", data: text }),
+ press: (key: string) =>
+ this.sendInputControl({ type: "KeyPress", data: key }),
moveMouse: (x: number, y: number) =>
this.sendInputControl({ type: "MouseMove", data: { x, y } }),
click: (button: "left" | "right" | "middle") =>
@@ -128,10 +136,50 @@ class NodePipe {
return {};
}
}
+
+ public async *streamTranscriptions(): AsyncGenerator<
+ TranscriptionStreamResponse,
+ void,
+ unknown
+ > {
+ const apiUrl = process.env.SCREENPIPE_SERVER_URL || "http://localhost:3030";
+ const eventSource = new EventSource(`${apiUrl}/sse/transcriptions`);
+
+ try {
+ while (true) {
+ const chunk: TranscriptionChunk = await new Promise(
+ (resolve, reject) => {
+ eventSource.onmessage = (event) => {
+ resolve(JSON.parse(event.data));
+ };
+ eventSource.onerror = (error) => {
+ reject(error);
+ };
+ }
+ );
+
+ yield {
+ id: crypto.randomUUID(),
+ object: "text_completion_chunk",
+ created: Date.now(),
+ model: "screenpipe-realtime",
+ choices: [
+ {
+ text: chunk.text,
+ index: 0,
+ finish_reason: chunk.is_final ? "stop" : null,
+ },
+ ],
+ };
+ }
+ } finally {
+ eventSource.close();
+ }
+ }
}
const pipe = new NodePipe();
export { pipe, toCamelCase, toSnakeCase, convertToCamelCase };
-export * from "../../common/types";
\ No newline at end of file
+export * from "../../common/types";
diff --git a/screenpipe-js/node-sdk/tests/streamTranscriptions.test.ts b/screenpipe-js/node-sdk/tests/streamTranscriptions.test.ts
new file mode 100644
index 000000000..9f0c0923e
--- /dev/null
+++ b/screenpipe-js/node-sdk/tests/streamTranscriptions.test.ts
@@ -0,0 +1,32 @@
+import { describe, expect, test } from "bun:test";
+import { pipe } from "../src/index";
+
+describe("streamTranscriptions", () => {
+ test(
+ "should receive and format transcription chunks",
+ async () => {
+ const chunks = [];
+
+ for await (const chunk of pipe.streamTranscriptions()) {
+ chunks.push(chunk);
+ if (chunks.length === 2) break; // Break after receiving both chunks
+ }
+
+ expect(chunks).toHaveLength(2);
+
+ // verify first chunk format
+ expect(chunks.length > 0).toBe(true);
+ },
+ { timeout: 10_000 }
+ );
+
+ test("should handle server errors gracefully", async () => {
+ try {
+ const generator = pipe.streamTranscriptions();
+ await generator.next();
+ expect(true).toBe(false); // should not reach here
+ } catch (error) {
+ expect(error).toBeDefined();
+ }
+ });
+});