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

refactor: move input api to pixel api, document better, add to mcp

Louis Beaumontc329a62d16c6
diff --git a/content/docs-mintlify-mig-tmp/operator-api.mdx b/content/docs-mintlify-mig-tmp/operator-api.mdx
index 4ae037d65..c1617019c 100644
--- a/content/docs-mintlify-mig-tmp/operator-api.mdx
+++ b/content/docs-mintlify-mig-tmp/operator-api.mdx
@@ -8,7 +8,9 @@ the operator api allows for powerful desktop automation using accessibility role
<Note>
compatibility note:
- operator api currently works on macos only. on windows/linux, please use the input control api
+ some functions of the operator api currently works on macos only. on windows/linux, please use the pixel api
+
+ [windows in progress](https://github.com/mediar-ai/screenpipe/pull/1694)
instead.
</Note>
@@ -97,18 +99,44 @@ async function simpleAutomation() {
the operator api provides a set of intuitive methods for automating desktop interactions:
-| method | description | example |
-| ---------------------------- | ------------------------------------ | ------------------------------------------------------- |
-| `openApplication(name)` | launches an application | `pipe.operator.openApplication("Chrome")` |
-| `openUrl(url, browser?)` | opens a url in a browser | `pipe.operator.openUrl("github.com")` |
-| `getByRole(role, options)` | finds elements by accessibility role | `pipe.operator.getByRole("button", {app: "Chrome"})` |
-| `getById(id, options)` | gets element by id | `pipe.operator.getById("element-123", {app: "Chrome"})` |
-| `.click()` | clicks an element | `pipe.operator.getById(id).click()` |
-| `.fill(text)` | enters text in a field | `pipe.operator.getById(id).fill("hello")` |
-| `.scroll(direction, amount)` | scrolls an element | `pipe.operator.getById(id).scroll("down", 300)` |
+| method | description | compatibility | example |
+| ------------------------------- | ------------------------------------ | ----------------- | ------------------------------------------------------- |
+| `openApplication(name)` | launches an application | macOS only | `pipe.operator.openApplication("Chrome")` |
+| `openUrl(url, browser?)` | opens a url in a browser | macOS only | `pipe.operator.openUrl("github.com")` |
+| `getByRole(role, options)` | finds elements by accessibility role | macOS only | `pipe.operator.getByRole("button", {app: "Chrome"})` |
+| `getById(id, options)` | gets element by id | macOS only | `pipe.operator.getById("element-123", {app: "Chrome"})` |
+| `.click()` | clicks an element | macOS only | `pipe.operator.getById(id).click()` |
+| `.fill(text)` | enters text in a field | macOS only | `pipe.operator.getById(id).fill("hello")` |
+| `.scroll(direction, amount)` | scrolls an element | macOS only | `pipe.operator.getById(id).scroll("down", 300)` |
+| `pixel.type(text)` | types text | all platforms | `pipe.operator.pixel.type("hello world")` |
+| `pixel.press(key)` | presses a keyboard key | all platforms | `pipe.operator.pixel.press("enter")` |
+| `pixel.moveMouse(x, y)` | moves mouse cursor to position | all platforms | `pipe.operator.pixel.moveMouse(100, 200)` |
+| `pixel.click(button)` | clicks mouse button | all platforms | `pipe.operator.pixel.click("left")` |
+
+### pixel api
+
+pixel API is a higher level API that is useful for:
+- controlling your iPhone through iPhone mirroring (because you cannot parse the screen of your iPhone)
+- Windows and Linux which does not support yet the functions like `openApplication`, `getByRole`, `click`, etc.
+
+```typescript
+// type text
+await pipe.operator.pixel.type("hello world")
+
+// press key
+await pipe.operator.pixel.press("enter")
+
+// move mouse
+await pipe.operator.pixel.moveMouse(100, 200)
+
+// click
+await pipe.operator.pixel.click("left") // "left" | "right" | "middle"
+```
## common accessibility roles
+to understand better roles, feel free to open MacOS Accessibility Inspector and see the roles for any application.
+
when using `getByRole()`, you'll need to specify the accessibility role. here are common ones:
- `"button"` - clickable buttons
@@ -365,4 +393,4 @@ if you're having issues with the operator api:
4. **debugging**: log element ids and roles to help identify the right elements
5. **app focus**: use the `activateApp: true` option to ensure the target app is in focus
-for more detailed debugging, use the macos accessibility inspector to identify exact roles and properties of ui elements.
\ No newline at end of file
+for more detailed debugging, use the macos accessibility inspector to identify exact roles and properties of ui elements.
diff --git a/content/docs-mintlify-mig-tmp/sdk-reference.mdx b/content/docs-mintlify-mig-tmp/sdk-reference.mdx
index 6fcc6cb26..4f5a341ae 100644
--- a/content/docs-mintlify-mig-tmp/sdk-reference.mdx
+++ b/content/docs-mintlify-mig-tmp/sdk-reference.mdx
@@ -788,68 +788,6 @@ async function streamMeetingInsights(settings: Settings) {
check out our [production pipe examples](https://github.com/mediar-ai/screenpipe/tree/main/pipes) on github to see more ai integration patterns.
-### operator api
-
-for detailed information about using the operator api for desktop automation, see the dedicated [operator api](/operator-api) page.
-
-OPERATOR ONLY WORKS ON MACOS FOR NOW - screenpipe backend need to be running also
-
-on Windows/Linux, please use the [input control api](#input-control-api) instead.
-
-to understand better roles, feel free to open MacOS Accessibility Inspector and see the roles for any application.
-
-### input control api
-
-requires building the backend with the `experimental` feature flag.
-
-`cargo build --release --features experimental`
-
-```typescript
-// type text
-await pipe.input.type("hello world")
-
-// press key
-await pipe.input.press("enter")
-
-// move mouse
-await pipe.input.moveMouse(100, 200)
-
-// click
-await pipe.input.click("left") // "left" | "right" | "middle"
-```
-
-#### automating repetitive tasks
-
-```typescript
-// Example: Automate filling a form
-async function fillForm() {
- // Move to input field and click
- await pipe.input.moveMouse(300, 200)
- await pipe.input.click("left")
-
- // Type name
- await pipe.input.type("John Doe")
-
- // Tab to next field
- await pipe.input.press("tab")
-
- // Type email
- await pipe.input.type("[email protected]")
-
- // Tab to next field
- await pipe.input.press("tab")
-
- // Type message
- await pipe.input.type("This is an automated message")
-
- // Submit form
- await pipe.input.press("tab")
- await pipe.input.press("enter")
-}
-
-// Call the function
-await fillForm()
-```
### notifications (desktop)
@@ -880,4 +818,4 @@ paste these links into your Cursor chat for context:
- https://github.com/mediar-ai/screenpipe/blob/main/screenpipe-js/browser-sdk/src/index.ts
- https://github.com/mediar-ai/screenpipe/blob/main/screenpipe-js/node-sdk/src/index.ts
-- https://github.com/mediar-ai/screenpipe/blob/main/screenpipe-js/common/Operator.ts
\ No newline at end of file
+- https://github.com/mediar-ai/screenpipe/blob/main/screenpipe-js/common/Operator.ts
diff --git a/screenpipe-integrations/screenpipe-mcp/src/screenpipe_mcp/server.py b/screenpipe-integrations/screenpipe-mcp/src/screenpipe_mcp/server.py
index 66e4cd31e..05643a55c 100644
--- a/screenpipe-integrations/screenpipe-mcp/src/screenpipe_mcp/server.py
+++ b/screenpipe-integrations/screenpipe-mcp/src/screenpipe_mcp/server.py
@@ -93,6 +93,46 @@ async def handle_list_tools() -> list[types.Tool]:
}
},
),
+ types.Tool(
+ name="pixel-control",
+ description=(
+ "Control mouse and keyboard at the pixel level. This is a cross-platform tool that works on all operating systems. "
+ "Use this to type text, press keys, move the mouse, and click buttons."
+ ),
+ inputSchema={
+ "type": "object",
+ "properties": {
+ "action_type": {
+ "type": "string",
+ "enum": ["WriteText", "KeyPress", "MouseMove", "MouseClick"],
+ "description": "Type of input action to perform",
+ },
+ "data": {
+ "oneOf": [
+ {
+ "type": "string",
+ "description": "Text to type or key to press (for WriteText and KeyPress)",
+ },
+ {
+ "type": "object",
+ "properties": {
+ "x": {"type": "integer", "description": "X coordinate for mouse movement"},
+ "y": {"type": "integer", "description": "Y coordinate for mouse movement"},
+ },
+ "description": "Coordinates for MouseMove",
+ },
+ {
+ "type": "string",
+ "enum": ["left", "right", "middle"],
+ "description": "Button to click for MouseClick",
+ },
+ ],
+ "description": "Action-specific data",
+ },
+ },
+ "required": ["action_type", "data"]
+ },
+ ),
]
# Add MacOS-specific tools only if running on MacOS
@@ -392,6 +432,53 @@ async def handle_call_tool(
text="Search Results:\n\n" + "\n".join(formatted_results)
)]
+ elif name == "pixel-control":
+ async with httpx.AsyncClient() as client:
+ try:
+ action = {
+ "type": arguments.get("action_type"),
+ "data": arguments.get("data")
+ }
+
+ response = await client.post(
+ f"{SCREENPIPE_API}/experimental/operator/pixel",
+ json={"action": action},
+ timeout=10.0
+ )
+ response.raise_for_status()
+ data = response.json()
+
+ if not data.get("success", False):
+ return [types.TextContent(
+ type="text",
+ text=f"failed to perform input control: {data.get('error', 'unknown error')}"
+ )]
+
+ action_type = arguments.get("action_type")
+ action_data = arguments.get("data")
+
+ if action_type == "WriteText":
+ result_text = f"successfully typed text: '{action_data}'"
+ elif action_type == "KeyPress":
+ result_text = f"successfully pressed key: '{action_data}'"
+ elif action_type == "MouseMove":
+ result_text = f"successfully moved mouse to coordinates: x={action_data.get('x')}, y={action_data.get('y')}"
+ elif action_type == "MouseClick":
+ result_text = f"successfully clicked {action_data} mouse button"
+ else:
+ result_text = "successfully performed input control action"
+
+ return [types.TextContent(
+ type="text",
+ text=result_text
+ )]
+
+ except Exception as e:
+ return [types.TextContent(
+ type="text",
+ text=f"failed to perform input control: {str(e)}"
+ )]
+
# MacOS-only tools from here
elif name == "click-element" and IS_MACOS:
async with httpx.AsyncClient() as client:
diff --git a/screenpipe-js/browser-sdk/package.json b/screenpipe-js/browser-sdk/package.json
index 80497501c..ec4faa448 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.39",
+ "version": "0.1.40",
"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.ts
index 5544e0942..aba515e30 100644
--- a/screenpipe-js/browser-sdk/src/index.ts
+++ b/screenpipe-js/browser-sdk/src/index.ts
@@ -1,7 +1,5 @@
import type {
EventStreamResponse,
- InputAction,
- InputControlResponse,
NotificationOptions,
ScreenpipeQueryParams,
ScreenpipeResponse,
@@ -99,36 +97,11 @@ async function* wsEvents(
}
}
-async function sendInputControl(action: InputAction): Promise<boolean> {
- const apiUrl = "http://localhost:3030";
- try {
- const response = await fetch(`${apiUrl}/experimental/input_control`, {
- method: "POST",
- headers: { "Content-Type": "application/json" },
- body: JSON.stringify({ action }),
- });
- if (!response.ok) {
- throw new Error(`http error! status: ${response.status}`);
- }
- const data: InputControlResponse = await response.json();
- return data.success;
- } catch (error) {
- console.error("failed to control input:", error);
- return false;
- }
-}
-
export interface BrowserPipe {
sendDesktopNotification(options: NotificationOptions): Promise<boolean>;
queryScreenpipe(
params: ScreenpipeQueryParams
): Promise<ScreenpipeResponse | null>;
- input: {
- type: (text: string) => Promise<boolean>;
- press: (key: string) => Promise<boolean>;
- moveMouse: (x: number, y: number) => Promise<boolean>;
- click: (button: "left" | "right" | "middle") => Promise<boolean>;
- };
operator: Operator;
streamTranscriptions(): AsyncGenerator<
TranscriptionStreamResponse,
@@ -448,20 +421,6 @@ class BrowserPipeImpl implements BrowserPipe {
}
}
- input: {
- type: (text: string) => Promise<boolean>;
- press: (key: string) => Promise<boolean>;
- moveMouse: (x: number, y: number) => Promise<boolean>;
- click: (button: "left" | "right" | "middle") => Promise<boolean>;
- } = {
- type: (text: string) => sendInputControl({ type: "WriteText", data: text }),
- press: (key: string) => sendInputControl({ type: "KeyPress", data: key }),
- moveMouse: (x: number, y: number) =>
- sendInputControl({ type: "MouseMove", data: { x, y } }),
- click: (button: "left" | "right" | "middle") =>
- sendInputControl({ type: "MouseClick", data: button }),
- };
-
pipes: {
list: () => Promise<Result<string[]>>;
enable: (pipeId: string) => Promise<boolean>;
diff --git a/screenpipe-js/common/Operator.ts b/screenpipe-js/common/Operator.ts
index 91f2352c0..c5c81ead0 100644
--- a/screenpipe-js/common/Operator.ts
+++ b/screenpipe-js/common/Operator.ts
@@ -60,11 +60,58 @@ export interface InteractableElementsResponse {
stats: ElementStats;
}
+export interface InputAction {
+ type: string;
+ data: any;
+}
+
+export interface InputControlResponse {
+ success: boolean;
+}
+
export class Operator {
private baseUrl: string;
+ public pixel: {
+ type: (text: string) => Promise<boolean>;
+ press: (key: string) => Promise<boolean>;
+ moveMouse: (x: number, y: number) => Promise<boolean>;
+ click: (button: "left" | "right" | "middle") => Promise<boolean>;
+ };
constructor(baseUrl: string = "http://localhost:3030") {
this.baseUrl = baseUrl;
+
+ this.pixel = {
+ 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") =>
+ this.sendInputControl({ type: "MouseClick", data: button }),
+ };
+ }
+
+ private async sendInputControl(action: InputAction): Promise<boolean> {
+ try {
+ const response = await fetch(
+ `${this.baseUrl}/experimental/operator/pixel`,
+ {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({ action }),
+ }
+ );
+ if (!response.ok) {
+ throw new Error(`http error! status: ${response.status}`);
+ }
+ const data: InputControlResponse = await response.json();
+ return data.success;
+ } catch (error) {
+ console.error("failed to control input:", error);
+ return false;
+ }
}
/**
diff --git a/screenpipe-js/node-sdk/package.json b/screenpipe-js/node-sdk/package.json
index 8f67fe209..5585592f0 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.20",
+ "version": "1.0.21",
"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.ts
index 6412f0628..1d9ba8f64 100644
--- a/screenpipe-js/node-sdk/src/index.ts
+++ b/screenpipe-js/node-sdk/src/index.ts
@@ -1,6 +1,4 @@
import type {
- InputAction,
- InputControlResponse,
ScreenpipeQueryParams,
ScreenpipeResponse,
NotificationOptions,
@@ -26,18 +24,6 @@ class NodePipe {
private analyticsInitialized = false;
private analyticsEnabled = true;
-
- public input = {
- 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") =>
- this.sendInputControl({ type: "MouseClick", data: button }),
- };
-
public settings = new SettingsManager();
public inbox = new InboxManager();
public pipes = new PipesManager();
@@ -63,26 +49,6 @@ class NodePipe {
}
}
- public async sendInputControl(action: InputAction): Promise<boolean> {
- await this.initAnalyticsIfNeeded();
- const apiUrl = process.env.SCREENPIPE_SERVER_URL || "http://localhost:3030";
- try {
- const response = await fetch(`${apiUrl}/experimental/input_control`, {
- method: "POST",
- headers: { "Content-Type": "application/json" },
- body: JSON.stringify({ action }),
- });
- if (!response.ok) {
- throw new Error(`http error! status: ${response.status}`);
- }
- const data: InputControlResponse = await response.json();
- return data.success;
- } catch (error) {
- console.error("failed to control input:", error);
- return false;
- }
- }
-
/**
* Query Screenpipe for content based on various filters.
*
diff --git a/screenpipe-server/src/server.rs b/screenpipe-server/src/server.rs
index 175a1bc08..8265f593d 100644
--- a/screenpipe-server/src/server.rs
+++ b/screenpipe-server/src/server.rs
@@ -1180,7 +1180,7 @@ impl SCServer {
open_application_handler,
)
.post("/experimental/operator/open-url", open_url_handler)
- .post("/experimental/input_control", input_control_handler)
+ .post("/experimental/operator/pixel", input_control_handler)
.post("/audio/start", start_audio)
.post("/audio/stop", stop_audio)
.get("/semantic-search", semantic_search_handler)