diff --git a/packages/contracts/src/client-gesture.ts b/packages/contracts/src/client-gesture.ts index 2b39fdfd54..19dfe8db23 100644 --- a/packages/contracts/src/client-gesture.ts +++ b/packages/contracts/src/client-gesture.ts @@ -2,12 +2,16 @@ import type { ClickButton } from './click-button.ts'; import type { GesturePointerCount } from './gesture-plan-types.ts'; -import type { GesturePayload } from './gesture-input.ts'; +import type { + DragGesturePayload, + GesturePayload, + SwipeGesturePayload, + TapGesturePayload, +} from './gesture-input.ts'; import type { ScrollDirection, ScrollInputDirection, SwipePattern, - SwipePreset, TransformGestureParams, } from './scroll-gesture.ts'; import type { SelectorSnapshotCommandOptions } from './client-capture.ts'; @@ -90,13 +94,7 @@ export type PanOptions = DeviceCommandBaseOptions & { durationMs?: number; }; -export type DragOptions = DeviceCommandBaseOptions & { - source: string; - destination: string; - sourceHoldMs?: number; - moveMs?: number; - destinationHoldMs?: number; -}; +export type DragOptions = DeviceCommandBaseOptions & Omit; export type FlingOptions = DeviceCommandBaseOptions & { direction: ScrollDirection; @@ -105,9 +103,7 @@ export type FlingOptions = DeviceCommandBaseOptions & { distance?: number; }; -export type SwipeGestureOptions = DeviceCommandBaseOptions & { - preset: SwipePreset; -}; +export type SwipeGestureOptions = DeviceCommandBaseOptions & Omit; export type FocusOptions = DeviceCommandBaseOptions & { x: number; @@ -147,12 +143,7 @@ export type RotateGestureOptions = DeviceCommandBaseOptions & { export type TransformGestureOptions = DeviceCommandBaseOptions & TransformGestureParams; /** Touches 2 to 5 points and holds them for `holdMs`; `count` repeats the same contacts. */ -export type TapGestureOptions = DeviceCommandBaseOptions & { - points: { x: number; y: number }[]; - holdMs?: number; - count?: number; - pauseMs?: number; -}; +export type TapGestureOptions = DeviceCommandBaseOptions & Omit; export type ScrollOptions = DeviceCommandBaseOptions & SettleCommandOptions & { diff --git a/src/agent-device-client.ts b/src/agent-device-client.ts index 2d7b1ae109..a7e0ce9613 100644 --- a/src/agent-device-client.ts +++ b/src/agent-device-client.ts @@ -18,7 +18,6 @@ import type { CaptureSnapshotResult, DaemonBinding, DaemonLifecycle, - DragOptions, FlingOptions, MaterializationReleaseOptions, PanOptions, @@ -26,8 +25,6 @@ import type { RotateGestureOptions, SessionSaveScriptOptions, SessionSaveScriptResult, - SwipeGestureOptions, - TapGestureOptions, TransformGestureOptions, } from '@agent-device/contracts/client'; import type { AgentArtifactsResult } from '@agent-device/contracts/observability'; @@ -458,11 +455,12 @@ export function createAgentDeviceClient( longPress: async (options) => await executeCommand('longpress', options), hover: async (options) => await executeCommand('hover', options), swipe: async (options) => await executeCommand('swipe', options), - pan: async (options) => await executeCommand('gesture', panGestureInput(options)), - drag: async (options) => await executeCommand('gesture', dragGestureInput(options)), + pan: async (options) => + await executeCommand('gesture', translatedGestureInput('pan', options)), + drag: async (options) => await executeCommand('gesture', { ...options, kind: 'drag' }), fling: async (options) => await executeCommand('gesture', flingGestureInput(options)), swipeGesture: async (options) => - await executeCommand('gesture', swipePresetGestureInput(options)), + await executeCommand('gesture', { ...options, kind: 'swipe' }), focus: async (options) => await executeCommand('focus', options), type: async (options) => await executeCommand('type', options), fill: async (options) => await executeCommand('fill', options), @@ -472,8 +470,8 @@ export function createAgentDeviceClient( rotateGesture: async (options) => await executeCommand('gesture', centeredGestureInput('rotate', options)), transformGesture: async (options) => - await executeCommand('gesture', transformGestureInput(options)), - tapGesture: async (options) => await executeCommand('gesture', tapGestureInput(options)), + await executeCommand('gesture', translatedGestureInput('transform', options)), + tapGesture: async (options) => await executeCommand('gesture', { ...options, kind: 'tap' }), get: async (options) => await executeCommand('get', options), is: async (options) => await executeCommand('is', options), find: async (options) => await executeCommand('find', options), @@ -512,13 +510,12 @@ export function createAgentDeviceClient( }; } -function panGestureInput(options: PanOptions): InternalRequestOptions & Record { +function translatedGestureInput( + kind: 'pan' | 'transform', + options: PanOptions | TransformGestureOptions, +): InternalRequestOptions & Record { const { x, y, dx, dy, ...common } = options; - return { ...common, kind: 'pan', origin: { x, y }, delta: { x: dx, y: dy } }; -} - -function dragGestureInput(options: DragOptions): InternalRequestOptions & Record { - return { ...options, kind: 'drag' }; + return { ...common, kind, origin: { x, y }, delta: { x: dx, y: dy } }; } function flingGestureInput( @@ -528,18 +525,14 @@ function flingGestureInput( return { ...common, kind: 'fling', origin: { x, y } }; } -function swipePresetGestureInput( - options: SwipeGestureOptions, -): InternalRequestOptions & Record { - return { ...options, kind: 'swipe' }; -} - function centeredGestureInput( kind: 'pinch' | 'rotate', options: PinchOptions | RotateGestureOptions, ): InternalRequestOptions & Record { const { x, y, ...common } = options; - assertCompleteGestureCenter(x, y, kind); + if ((x === undefined) !== (y === undefined)) { + throw new AppError('INVALID_ARGS', `gesture ${kind} center requires both x and y`); + } return { ...common, kind, @@ -547,29 +540,6 @@ function centeredGestureInput( }; } -function transformGestureInput( - options: TransformGestureOptions, -): InternalRequestOptions & Record { - const { x, y, dx, dy, ...common } = options; - return { ...common, kind: 'transform', origin: { x, y }, delta: { x: dx, y: dy } }; -} - -function tapGestureInput( - options: TapGestureOptions, -): InternalRequestOptions & Record { - return { ...options, kind: 'tap' }; -} - -function assertCompleteGestureCenter( - x: number | undefined, - y: number | undefined, - gesture: 'pinch' | 'rotate', -): void { - if ((x === undefined) !== (y === undefined)) { - throw new AppError('INVALID_ARGS', `gesture ${gesture} center requires both x and y`); - } -} - function normalizeSnapshotResult( data: Record, session: string | undefined,