feat: add @droidclaw/shared types package
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
14
packages/shared/package.json
Normal file
14
packages/shared/package.json
Normal file
@@ -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"
|
||||
}
|
||||
}
|
||||
2
packages/shared/src/index.ts
Normal file
2
packages/shared/src/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from "./types.js";
|
||||
export * from "./protocol.js";
|
||||
41
packages/shared/src/protocol.ts
Normal file
41
packages/shared/src/protocol.ts
Normal file
@@ -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<string, unknown>; reasoning: string; screenHash: string }
|
||||
| { type: "goal_started"; sessionId: string; goal: string; deviceId: string }
|
||||
| { type: "goal_completed"; sessionId: string; success: boolean; stepsUsed: number };
|
||||
66
packages/shared/src/types.ts
Normal file
66
packages/shared/src/types.ts
Normal file
@@ -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<string, string>;
|
||||
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;
|
||||
}
|
||||
14
packages/shared/tsconfig.json
Normal file
14
packages/shared/tsconfig.json
Normal file
@@ -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"]
|
||||
}
|
||||
Reference in New Issue
Block a user