shellx-ai 1.0.11 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +586 -0
  3. package/dist/automation/element-finder.d.ts +189 -0
  4. package/dist/automation/element-finder.js +322 -0
  5. package/dist/automation/element-finder.js.map +1 -0
  6. package/dist/automation/ui-action-handler.d.ts +330 -0
  7. package/dist/automation/ui-action-handler.js +873 -0
  8. package/dist/automation/ui-action-handler.js.map +1 -0
  9. package/dist/cbor-compat.d.ts +27 -0
  10. package/dist/cbor-compat.js +108 -0
  11. package/dist/cbor-compat.js.map +1 -0
  12. package/dist/domain-manager.d.ts +80 -0
  13. package/dist/domain-manager.js +158 -0
  14. package/dist/domain-manager.js.map +1 -0
  15. package/dist/error-handler.d.ts +87 -0
  16. package/dist/error-handler.js +148 -0
  17. package/dist/error-handler.js.map +1 -0
  18. package/dist/errors.d.ts +114 -0
  19. package/dist/errors.js +139 -0
  20. package/dist/errors.js.map +1 -0
  21. package/dist/index.d.ts +163 -54
  22. package/dist/index.js +712 -472
  23. package/dist/index.js.map +1 -0
  24. package/dist/logger.d.ts +81 -0
  25. package/dist/logger.js +128 -0
  26. package/dist/logger.js.map +1 -0
  27. package/dist/protocol.d.ts +147 -31
  28. package/dist/protocol.js +2 -2
  29. package/dist/protocol.js.map +1 -0
  30. package/dist/shell/output-buffer.d.ts +152 -0
  31. package/dist/shell/output-buffer.js +163 -0
  32. package/dist/shell/output-buffer.js.map +1 -0
  33. package/dist/shell/shell-command-executor.d.ts +182 -0
  34. package/dist/shell/shell-command-executor.js +348 -0
  35. package/dist/shell/shell-command-executor.js.map +1 -0
  36. package/dist/shellx.d.ts +681 -176
  37. package/dist/shellx.js +763 -1047
  38. package/dist/shellx.js.map +1 -0
  39. package/dist/types.d.ts +132 -57
  40. package/dist/types.js +4 -4
  41. package/dist/types.js.map +1 -0
  42. package/dist/utils/retry-helper.d.ts +73 -0
  43. package/dist/utils/retry-helper.js +92 -0
  44. package/dist/utils/retry-helper.js.map +1 -0
  45. package/dist/utils.d.ts +3 -3
  46. package/dist/utils.js +17 -23
  47. package/dist/utils.js.map +1 -0
  48. package/package.json +95 -59
@@ -0,0 +1,330 @@
1
+ /**
2
+ * UIActionHandler - A module for handling UI automation actions
3
+ *
4
+ * This module provides functionality for executing various UI actions such as
5
+ * clicking, inputting text, swiping, pressing keys, and more.
6
+ */
7
+ import type { ElementSelector, ActionSequence as LegacyActionSequence, ScreenShotOptions, ScreenInfoResponse, ScreenShotResponse } from "../protocol.js";
8
+ import type { Click, ClickResult, Input, InputResult, Swipe, SwipeResult, Key, KeyResult, Wait, WaitResult, Clipboard, ClipboardResult, AppInfo, AppInfoResult, Screenshot, ScreenshotResult } from "../types.js";
9
+ /**
10
+ * Interface for ConnectionClient methods used by UIActionHandler
11
+ */
12
+ interface IConnectionClient {
13
+ findElement(selector: ElementSelector, options?: unknown): Promise<{
14
+ elements?: unknown[];
15
+ } | undefined>;
16
+ executeAction(action: LegacyActionSequence): Promise<void>;
17
+ sendMessageWithTaskId<T = unknown>(message: unknown, type: string, options?: {
18
+ timeout?: number;
19
+ taskId?: string;
20
+ }): Promise<{
21
+ promise: Promise<T>;
22
+ }>;
23
+ screenShot(options: ScreenShotOptions): Promise<ScreenShotResponse>;
24
+ getScreenInfo(): Promise<ScreenInfoResponse>;
25
+ }
26
+ /**
27
+ * App list response types
28
+ */
29
+ interface DeviceAppInfo {
30
+ packageName: string;
31
+ appName: string;
32
+ versionName: string;
33
+ versionCode: number;
34
+ isSystemApp: boolean;
35
+ isEnabled: boolean;
36
+ firstInstallTime: number;
37
+ lastUpdateTime: number;
38
+ sourceDir: string;
39
+ }
40
+ interface AppListResult {
41
+ apps: DeviceAppInfo[];
42
+ totalCount: number;
43
+ systemAppCount: number;
44
+ userAppCount: number;
45
+ timestamp: number;
46
+ success: boolean;
47
+ error?: string;
48
+ }
49
+ /**
50
+ * UIActionHandler class handles UI automation operations
51
+ *
52
+ * This class provides methods to:
53
+ * - Execute UI actions (click, input, swipe, key press)
54
+ * - Wait for elements
55
+ * - Take screenshots
56
+ * - Execute action sequences
57
+ * - Navigate through app UI
58
+ */
59
+ export declare class UIActionHandler {
60
+ private client;
61
+ private elementFinder;
62
+ private logger;
63
+ /**
64
+ * Creates a UIActionHandler instance
65
+ *
66
+ * @param client - The ConnectionClient instance for UI operations
67
+ */
68
+ constructor(client: IConnectionClient);
69
+ /**
70
+ * Validate that client is initialized
71
+ *
72
+ * @returns true if client is valid, false otherwise
73
+ */
74
+ private validateClient;
75
+ /**
76
+ * Convert simplified selector to protocol selector
77
+ *
78
+ * @param selector - Simplified selector object
79
+ * @returns Protocol ElementSelector object
80
+ */
81
+ private convertSelector;
82
+ /**
83
+ * Execute action and verify it succeeded
84
+ *
85
+ * @param action - The action sequence to execute
86
+ */
87
+ private executeAndVerifyAction;
88
+ /**
89
+ * Execute operation with retry and unified error handling
90
+ *
91
+ * @param operation - Async operation to execute
92
+ * @param startTime - Operation start time
93
+ * @param options - Retry and error handling options
94
+ * @returns Promise resolving to operation result
95
+ */
96
+ private executeWithRetry;
97
+ /**
98
+ * Execute a click action
99
+ *
100
+ * @param clickData - Click configuration
101
+ * @returns Promise resolving to ClickResult
102
+ *
103
+ * @example
104
+ * ```typescript
105
+ * const result = await actionHandler.click({
106
+ * elementId: 'element123',
107
+ * clickType: 'single',
108
+ * wait: 3000
109
+ * });
110
+ * ```
111
+ */
112
+ click(clickData: Click): Promise<ClickResult>;
113
+ /**
114
+ * Execute an input action
115
+ *
116
+ * @param inputData - Input configuration
117
+ * @returns Promise resolving to ActionResult
118
+ *
119
+ * @example
120
+ * ```typescript
121
+ * const result = await actionHandler.input({
122
+ * elementId: 'element123',
123
+ * text: 'Hello World',
124
+ * clear: true,
125
+ * hideKeyboard: false,
126
+ * wait: 500
127
+ * });
128
+ * ```
129
+ */
130
+ input(inputData: Input): Promise<InputResult>;
131
+ /**
132
+ * Execute a swipe action
133
+ *
134
+ * @param swipeData - Swipe configuration
135
+ * @returns Promise resolving to ActionResult
136
+ *
137
+ * @example
138
+ * ```typescript
139
+ * const result = await actionHandler.swipe({
140
+ * fromX: 500,
141
+ * fromY: 1000,
142
+ * toX: 500,
143
+ * toY: 500,
144
+ * duration: 800,
145
+ * wait: 500
146
+ * });
147
+ * ```
148
+ */
149
+ swipe(swipeData: Swipe): Promise<SwipeResult>;
150
+ /**
151
+ * Execute a key press action
152
+ *
153
+ * @param keyData - Key configuration
154
+ * @returns Promise resolving to ActionResult
155
+ *
156
+ * @example
157
+ * ```typescript
158
+ * const result = await actionHandler.pressKey({
159
+ * key: 'KEYCODE_BACK',
160
+ * longPress: false,
161
+ * wait: 500
162
+ * });
163
+ * ```
164
+ */
165
+ pressKey(keyData: Key): Promise<KeyResult>;
166
+ /**
167
+ * Wait for an element condition
168
+ *
169
+ * @param waitData - Wait configuration
170
+ * @returns Promise resolving to ActionResult
171
+ *
172
+ * @example
173
+ * ```typescript
174
+ * // Wait for element to appear
175
+ * const result = await actionHandler.wait({
176
+ * text: 'Submit',
177
+ * condition: 'visible',
178
+ * timeout: 10000
179
+ * });
180
+ *
181
+ * // Wait for element to disappear
182
+ * const result = await actionHandler.wait({
183
+ * text: 'Loading',
184
+ * condition: 'gone',
185
+ * timeout: 10000
186
+ * });
187
+ * ```
188
+ */
189
+ wait(waitData: Wait): Promise<WaitResult>;
190
+ /**
191
+ * Execute a clipboard action
192
+ *
193
+ * @param clipboardData - Clipboard configuration
194
+ * @returns Promise resolving to ActionResult
195
+ *
196
+ * @example
197
+ * ```typescript
198
+ * // Get clipboard content
199
+ * const result = await actionHandler.clipboard({ get: true });
200
+ *
201
+ * // Set clipboard content
202
+ * const result = await actionHandler.clipboard({
203
+ * text: 'Hello',
204
+ * paste: false
205
+ * });
206
+ *
207
+ * // Paste clipboard content
208
+ * const result = await actionHandler.clipboard({ paste: true });
209
+ * ```
210
+ */
211
+ clipboard(clipboardData: Clipboard): Promise<ClipboardResult>;
212
+ /**
213
+ * Take a screenshot
214
+ *
215
+ * @param screenshotData - Screenshot configuration
216
+ * @returns Promise resolving to ActionResult
217
+ *
218
+ * @example
219
+ * ```typescript
220
+ * const result = await actionHandler.takeScreenshot({
221
+ * format: 'png',
222
+ * quality: 100,
223
+ * scale: 1,
224
+ * saveToFile: true
225
+ * });
226
+ * ```
227
+ */
228
+ takeScreenshot(screenshotData?: Screenshot): Promise<ScreenshotResult>;
229
+ /**
230
+ * Get application info
231
+ *
232
+ * @param appInfoData - App info configuration
233
+ * @returns Promise resolving to ActionResult
234
+ *
235
+ * @example
236
+ * ```typescript
237
+ * const result = await actionHandler.getAppInfo({
238
+ * package: 'com.example.app',
239
+ * retry: 3
240
+ * });
241
+ * ```
242
+ */
243
+ getAppInfo(appInfoData: AppInfo): Promise<AppInfoResult>;
244
+ /**
245
+ * Get screen information
246
+ *
247
+ * @returns Promise resolving to ScreenInfoResponse
248
+ *
249
+ * @example
250
+ * ```typescript
251
+ * const screenInfo = await actionHandler.getScreenInfo();
252
+ * console.log(`Screen size: ${screenInfo.width}x${screenInfo.height}`);
253
+ * ```
254
+ */
255
+ getScreenInfo(): Promise<ScreenInfoResponse>;
256
+ /**
257
+ * Get list of installed applications
258
+ *
259
+ * @param options - Options for filtering app list
260
+ * @returns Promise resolving to app list response
261
+ *
262
+ * @example
263
+ * ```typescript
264
+ * const result = await actionHandler.getAppList({
265
+ * includeSystemApps: false,
266
+ * includeDisabledApps: false
267
+ * });
268
+ * console.log(`Found ${result.userAppCount} user apps`);
269
+ * ```
270
+ */
271
+ getAppList(options?: {
272
+ includeSystemApps?: boolean;
273
+ includeDisabledApps?: boolean;
274
+ }): Promise<AppListResult>;
275
+ /**
276
+ * Navigate through app using a series of text-based clicks
277
+ *
278
+ * @param textPath - Array of text strings to click in sequence
279
+ * @returns Promise resolving to boolean indicating success
280
+ *
281
+ * @example
282
+ * ```typescript
283
+ * const success = await actionHandler.navigateByPath([
284
+ * 'Settings',
285
+ * 'Accounts',
286
+ * 'Add Account'
287
+ * ]);
288
+ * ```
289
+ */
290
+ navigateByPath(textPath: string[]): Promise<boolean>;
291
+ /**
292
+ * Click element by text content
293
+ *
294
+ * @param text - Text content to search for
295
+ * @param exact - Whether to match exact text (default: false)
296
+ * @returns Promise resolving to boolean indicating success
297
+ *
298
+ * @example
299
+ * ```typescript
300
+ * // Click element containing text
301
+ * await actionHandler.clickByText('Submit');
302
+ *
303
+ * // Click element with exact text match
304
+ * await actionHandler.clickByText('Submit', true);
305
+ * ```
306
+ */
307
+ clickByText(text: string, exact?: boolean): Promise<boolean>;
308
+ /**
309
+ * Input text into a field
310
+ *
311
+ * @param selector - Element selector
312
+ * @param text - Text to input
313
+ * @param options - Additional options
314
+ * @returns Promise resolving to boolean indicating success
315
+ *
316
+ * @example
317
+ * ```typescript
318
+ * await actionHandler.inputText(
319
+ * { resourceId: 'username_field' },
320
+ * 'john.doe',
321
+ * { clear: true, hideKeyboard: false }
322
+ * );
323
+ * ```
324
+ */
325
+ inputText(selector: ElementSelector, text: string, options?: {
326
+ clear?: boolean;
327
+ hideKeyboard?: boolean;
328
+ }): Promise<boolean>;
329
+ }
330
+ export {};