diff --git a/packages/shared/package.json b/packages/shared/package.json new file mode 100644 index 0000000..dc8b00d --- /dev/null +++ b/packages/shared/package.json @@ -0,0 +1,14 @@ +{ + "name": "@droidclaw/shared", + "version": "0.0.1", + "type": "module", + "exports": { + ".": "./src/index.ts" + }, + "scripts": { + "typecheck": "tsc --noEmit" + }, + "devDependencies": { + "typescript": "^5.9.2" + } +} diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.ts new file mode 100644 index 0000000..aeea426 --- /dev/null +++ b/packages/shared/src/index.ts @@ -0,0 +1,2 @@ +export * from "./types.js"; +export * from "./protocol.js"; diff --git a/packages/shared/src/protocol.ts b/packages/shared/src/protocol.ts new file mode 100644 index 0000000..420cd56 --- /dev/null +++ b/packages/shared/src/protocol.ts @@ -0,0 +1,41 @@ +import type { UIElement, DeviceInfo } from "./types.js"; + +export type DeviceMessage = + | { type: "auth"; apiKey: string; deviceInfo?: DeviceInfo } + | { type: "screen"; requestId: string; elements: UIElement[]; screenshot?: string; packageName?: string } + | { type: "result"; requestId: string; success: boolean; error?: string; data?: string } + | { type: "goal"; text: string } + | { type: "pong" }; + +export type ServerToDeviceMessage = + | { type: "auth_ok"; deviceId: string } + | { type: "auth_error"; message: string } + | { type: "get_screen"; requestId: string } + | { type: "tap"; requestId: string; x: number; y: number } + | { type: "type"; requestId: string; text: string } + | { type: "swipe"; requestId: string; x1: number; y1: number; x2: number; y2: number; duration?: number } + | { type: "enter"; requestId: string } + | { type: "back"; requestId: string } + | { type: "home"; requestId: string } + | { type: "longpress"; requestId: string; x: number; y: number } + | { type: "launch"; requestId: string; packageName: string } + | { type: "clear"; requestId: string } + | { type: "clipboard_set"; requestId: string; text: string } + | { type: "clipboard_get"; requestId: string } + | { type: "paste"; requestId: string } + | { type: "open_url"; requestId: string; url: string } + | { type: "switch_app"; requestId: string; packageName: string } + | { type: "notifications"; requestId: string } + | { type: "keyevent"; requestId: string; code: number } + | { type: "open_settings"; requestId: string } + | { type: "wait"; requestId: string; duration?: number } + | { type: "ping" } + | { type: "goal_started"; sessionId: string; goal: string } + | { type: "goal_completed"; sessionId: string; success: boolean; stepsUsed: number }; + +export type DashboardMessage = + | { type: "device_online"; deviceId: string; name: string } + | { type: "device_offline"; deviceId: string } + | { type: "step"; sessionId: string; step: number; action: Record; reasoning: string; screenHash: string } + | { type: "goal_started"; sessionId: string; goal: string; deviceId: string } + | { type: "goal_completed"; sessionId: string; success: boolean; stepsUsed: number }; diff --git a/packages/shared/src/types.ts b/packages/shared/src/types.ts new file mode 100644 index 0000000..11b7863 --- /dev/null +++ b/packages/shared/src/types.ts @@ -0,0 +1,66 @@ +export interface UIElement { + id: string; + text: string; + type: string; + bounds: string; + center: [number, number]; + size: [number, number]; + clickable: boolean; + editable: boolean; + enabled: boolean; + checked: boolean; + focused: boolean; + selected: boolean; + scrollable: boolean; + longClickable: boolean; + password: boolean; + hint: string; + action: "tap" | "type" | "longpress" | "scroll" | "read"; + parent: string; + depth: number; +} + +export interface ActionDecision { + action: string; + coordinates?: [number, number]; + text?: string; + direction?: string; + reason?: string; + package?: string; + activity?: string; + uri?: string; + extras?: Record; + command?: string; + filename?: string; + think?: string; + plan?: string[]; + planProgress?: string; + skill?: string; + query?: string; + url?: string; + path?: string; + source?: string; + dest?: string; + code?: number; + setting?: string; +} + +export interface ActionResult { + success: boolean; + message: string; + data?: string; +} + +export interface DeviceInfo { + model: string; + androidVersion: string; + screenWidth: number; + screenHeight: number; +} + +export interface ScreenState { + elements: UIElement[]; + screenshot?: string; + packageName?: string; + fallbackReason?: string; +} diff --git a/packages/shared/tsconfig.json b/packages/shared/tsconfig.json new file mode 100644 index 0000000..582e96c --- /dev/null +++ b/packages/shared/tsconfig.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "target": "ES2022", + "module": "ES2022", + "moduleResolution": "bundler", + "strict": true, + "esModuleInterop": true, + "skipLibCheck": true, + "declaration": true, + "outDir": "dist", + "rootDir": "src" + }, + "include": ["src/**/*.ts"] +}